Commit graph

8183 commits

Author SHA1 Message Date
Petr Pchelko
bc6f7e4bdc Make User implement Authority
Ideally, only User associated with the global request
should be associated with UserAuthority. For a random
user instance, not the current performer, checking permissions
should be based solely on user groups and perhaps an
existing block. Right now however, PermissionManager
is coupled with global request, so we still instantiate
a UserAuthority for non-current users. This mimics the
behaviour we've had before. As we refactor PermissionManager,
we will be able to replace Authority implementation in this case,
or even entirely prohibit non-performer authority.

Bug: T271459
Depends-On: Iebf2dca34eea751391d9740443c195287399aa5c
Change-Id: Ib094e498fd883db23f2763f171281b1c9e99217e
2021-01-19 18:08:12 -06:00
daniel
10ccdb2281 Define equality for PageIdentity and LinkTarget
Bug: T272420
Change-Id: I2e0eb21989e2d733088ab77d7461bf003c2905eb
2021-01-19 23:07:37 +00:00
jenkins-bot
5db4b26fb4 Merge "Strict return types for PageIdentity" 2021-01-19 21:35:30 +00:00
daniel
6a47d51726 RevisionRecord: add getPage()
Provide a path from RevisionRecord to PageIdentity.

Bug: T208776
Change-Id: I7598c4cf207b50714a1e3ba246bb95986399b6f1
2021-01-19 15:28:09 +00:00
daniel
61a5531e4a Strict return types for PageIdentity
Bug: T208776
Change-Id: I7e71ffc209465b7cca385603d844cd40178485a9
2021-01-18 17:33:14 +01:00
James D. Forrester
a547ef3b9e Revert "Make WikiPage a ProperPageIdentity"
This reverts commit 8f46ef5ff4.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I67de3dbbbc9163aae937f710ecb0e40db0d483a0
2021-01-15 12:30:30 -08:00
James D. Forrester
a8fe6c9841 Revert "Define equality for PageIdentity and LinkTarget"
This reverts commit 36f1adf670.

This has seemingly broken FlaggedRevs and thus a bunch of repos.

Bug: T272170
Change-Id: I26c6fd656c75a6b209fb17965dc9109edf68642b
2021-01-15 12:30:14 -08:00
jenkins-bot
6017caafbc Merge "Define equality for PageIdentity and LinkTarget" 2021-01-15 17:23:37 +00:00
daniel
36f1adf670 Define equality for PageIdentity and LinkTarget
This allows Title and WikiPage objects to be compared with PageIdentity
and LinkTarget instances consistently.

Change-Id: I1bbd15d17d046359393ecfc1acd2778273260a95
2021-01-15 17:53:28 +01:00
jenkins-bot
398c39b6de Merge "deferred: make DeferredUpdates::doUpdates() recursion more uniform" 2021-01-15 16:52:31 +00:00
jenkins-bot
9fe9d76577 Merge "Make WikiPage a ProperPageIdentity" 2021-01-15 16:17:44 +00:00
daniel
8f46ef5ff4 Make WikiPage a ProperPageIdentity
This makes it so methods that take a WikiPage can be narrowed to a
PageIdentity, and prepares WikiPage for the introduction of the PageRecord
interface.

Bug: T208776
Change-Id: Iab8bd75a1948873baab9c91c76f966d606b23c0f
2021-01-15 12:34:24 +01:00
DannyS712
edb2072c68 Remove unused definition of NS_UNITTEST(_TALK) in UserTest
Change-Id: I813f188050183aa468feb9ca877b7d238c6dd09d
2021-01-15 10:37:02 +00:00
DannyS712
18eee995b3 Remove WatchedItemStoreUnitTest::getFakeRow
Replace with (object) casts

Change-Id: Ib1c9e1b7a6e038223f7b2308c9913da752b8db68
2021-01-15 09:21:48 +00:00
DannyS712
be174c4dc1 Make WatchedItemQueryServiceUnitTest a pure unit test
The `testGetWatchedItemsWithRecentChangeInfo_watchlistOwnerAndInvalidToken`
method (and its data provider) moved to the remaining integration test,
since those actually do require integration

Also do some minor clean up to the unit tests:
* Replace ::getFakeRow with manual (object) casts
* Combine duplicate getMockNonAnonUserWithIdAndRestrictedPermissions
and getMockNonAnonUserWithIdAndNoPatrolRights

Change-Id: Ie853f465b39f06dadd65582df061a9c44068b63a
2021-01-15 00:50:18 -08:00
jenkins-bot
cb2dbd01b5 Merge "Improve some function documentation in tests" 2021-01-15 08:44:01 +00:00
jenkins-bot
fc25878444 Merge "WatchedItemStore: Use REPLACE when inserting expiries after page move" 2021-01-15 05:28:46 +00:00
Aaron Schulz
4b7ddd3c67 deferred: make DeferredUpdates::doUpdates() recursion more uniform
Follow-up ba6490aa1e.

That patch worked around $executeContext iteration errors due to the
lack of recursion support in doUpdates()/handleUpdateQueue(). Errors
were triggered by MediaWiki::schedulePostSendJobs() enqueueing deferred
updates that invoke JobRunner::run(), which, in turn, invoke doUpdates()
for each job via JobRunner:: doExecuteJob(). The doUpdates() method was
changed to operate on the sub-queue for the in-progress DeferrableUpdate.

Further improve the recursion logic:
* Use classes for the scope stack and scope queues.
* Put *all* updates added during a DeferrableUpdate::doUpdate() call into
  the subqueue, regardless of "defer until" stage or whether it implements
  MergeableUpdate. Now, doUpdate() can run *everything* it enqueued instead
  of a non-obvious subset. Note that the TransactionRoundDefiningUpdate
  that invokes JobRunner was already a POSTSEND update before ba6490aa1eb;
  the only effect of this change is that MergeableUpdate instances from jobs
  will once again run in doExecuteJob().
* Make recursive DeferredUpdates::doUpdate() calls error out immediately
  unless the DeferrableUpdate responsible is a TransactionRoundAwareUpdate
  with the TRX_ROUND_ABSENT flag. This covers the schedulePostSendJobs()
  scenario and only prohibits insane call patterns. Failing early avoids
  the risk of handleUpdateQueue() dropping all the updates due to the same
  DBTransactionError error in DeferredUpdates::attemptUpdate().
* Avoid recursion loop in tryOpportunisticExecute() when JobQueueDB is in
  use and a large number of tasks are pending. This happened due to methods
  like onTransactionPreCommitOrIdle() being used within JobQueueDB.

Mark DeferredUpdates::doUpdates()/tryOpportunisticExecute() as @internal
and create a Maintenance::shutdown() method to avoid a direct call in the
doMaintenance.php file.

Bug: T249069
Bug: T268840
Change-Id: Ib369f0e74243a48ababdb9cd83b155c9a0f5e741
2021-01-14 15:37:58 -08:00
Umherirrender
0347fd0631 Improve some function documentation in tests
Also fix some whitespaces

Change-Id: Ibed50a4f07442d3f299cf545c16f5dbb5f27a411
2021-01-14 22:13:55 +01:00
jenkins-bot
5f7e7fb238 Merge "Make WatchedItemUnitTest a pure unit test" 2021-01-14 20:13:51 +00:00
jenkins-bot
dccd62660a Merge "Introduce PageIdentity interface" 2021-01-14 20:12:09 +00:00
MusikAnimal
56ccf11a6c WatchedItemStore: Use REPLACE when inserting expiries after page move
Sometimes when moving pages, a row for the target page may already exist
in the watchlist_expiry table. The exact scenario that's causing the
prod errors could not be repo'd in tests or locally, but using REPLACE
should be a safe solution.

Tests updated to actually verify the expiry of the new title, if
present, is overriden with the old one following the page move.

Bug: T271971
Change-Id: Id4d46fcdea4816e5714d266985ba86fdc6450cfb
2021-01-14 14:22:06 -05:00
daniel
1a60008a9a Introduce PageIdentity interface
PageIdentity is intended as a lightweight alternative to Title,
similar to LinkTarget, but providing a page ID. It follows the precedent
of UserIdentity.

Bug: T208776
Change-Id: Iaed4871e0d32c67d4fb13e487625527f6a21e9c5
2021-01-14 13:18:05 -06:00
Thiemo Kreuz
ac205fa84c Fix incomplete/bogus PHPDoc tags in various tests
Most of these are found by the not yet released I10559d8.

I remove the type MockObject in some cases when the calling
code really does not need to know if he get's a mock or the
real thing. However, I do this only in places that are very
closely related to the fixes.

Change-Id: I26a4c3c5a8ae141bf56161b52b54bce7e68f2e30
2021-01-14 19:02:00 +00:00
jenkins-bot
1a94be9c2a Merge "Feature file styles should precede module defined ones" 2021-01-13 14:24:44 +00:00
jenkins-bot
658cb99a4b Merge "Emit deprecation warning for deprecated overrides." 2021-01-13 04:06:55 +00:00
jenkins-bot
655b3fbc04 Merge "Fix access to services in unit tests." 2021-01-12 23:24:15 +00:00
jdlrobson
f1457312dc Feature file styles should precede module defined ones
In the case of Monobook, Monobook styles were overriding a
normalize rule and failing to work.

Bug: T269618
Change-Id: Ifa346f60e3a50d874e68043dc4dece3fd8b41aa3
2021-01-12 14:04:02 -08:00
daniel
68968305e3 Fix undefined index error in ApiQueryInfo
The code didn't properly handle requests for info about non-existing
pages.

Bug: T271804
Bug: T271815
Change-Id: If4e56ff5ecb4a048767833c89847bb58269cad43
2021-01-12 15:29:52 +00:00
DannyS712
9188f6cf7a Make WatchedItemUnitTest a pure unit test
Change-Id: If390e61d4d4800b1d20a5d0bec87f9aa7ad83e10
2021-01-12 11:56:25 +00:00
jenkins-bot
0259ec87a7 Merge "Safer autoloading with respect to file-scope code" 2021-01-12 10:23:28 +00:00
daniel
483c1a6643 Fix access to services in unit tests.
PHPUnit tests that are not based on MediaWikiIntegrationTestCase must
not access the global service container. This patch fixes two instances:

* GlobalIdGeneratorTest was tsting the getTimestampFromUUIDv1 via the
legacy static method in UIDGenerator. Changed to test the GlobalIdGenerator
method directly. Tests for the deprecated static methods should be
separate, if needed at all.

* DerivativeResourceLoaderContextTest does not reside under the "unit"
directory for strict unit tests, but was not based on
MediaWikiIntegrationTestCase, even though ResourceLoader logic heavily
relies on the global service container instance. Fixed by deriving the
test class from MediaWikiIntegrationTestCase.

Change-Id: I40b8364edc5bd88d60e62b0cd0fa51c6ae9d2298
2021-01-12 10:55:11 +01:00
jenkins-bot
065aaa3ddc Merge "Revert "Enhance GroupPermissionsLookup and use it."" 2021-01-12 05:39:15 +00:00
jenkins-bot
7200e36c9f Merge "parser: convert Preprocessor to WANCache and inject dependencies" 2021-01-12 05:04:47 +00:00
jenkins-bot
ca34763bb8 Merge "WikiPage: Add process cache for content model" 2021-01-12 04:54:06 +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
Aaron Schulz
de6eeead21 parser: convert Preprocessor to WANCache and inject dependencies
Make the caching logic use getWithSetCallback() and simplify
the code given that there is only one Preprocessor subclass.
Also, keep the cached values JSON serializable but rely on
the serialization in BagOStuff instead for simplicity.

Add related class constants for injecting preprocessor flags.

Bug: T254608
Change-Id: I72f9f0c0bc352ed5120469090c71294ff0c24999
2021-01-11 20:21:10 -08:00
jenkins-bot
87f373579c Merge "WatchedItemStore: use UserFactory" 2021-01-12 00:28:58 +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
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
DannyS712
b40ca337c9 WatchedItemStore: use UserFactory
Will allow for converting to true Unit tests

Change-Id: I0ef2ada0d5ee9a80a104cb9b07a50e3887d02dd3
2021-01-10 03:12:25 +00:00
jenkins-bot
44252a899c Merge "Add helpful @var tags to BlockManagerTest" 2021-01-08 20:45:38 +00:00
Timo Tijhof
a53a38ec5e phpunit: Remove odd "MediaWiki" group from tests using it
Doesn't appear to have any meaning.

Change-Id: Id12599874f7f5bd727693b9decb190e9d5c7305d
2021-01-08 18:35:30 +00:00
daniel
8a7d487545 Emit deprecation warning for deprecated overrides.
This introduces a utility method in MWDebug, and uses it to clean up
the deprecation mechanism for Skin::setupSkinUserCss().

Bug: T257990
Bug: T267080
Change-Id: I5b07fa82dcc2b0fd112f122e45c9b2562cd09247
2021-01-08 19:33:57 +01:00
jenkins-bot
7b7082f9c0 Merge "Introduce GroupPermissionsLookup" 2021-01-08 17:47:26 +00:00
Thiemo Kreuz
7166284835 Add helpful @var tags to BlockManagerTest
Without these IDEs mark method calls on the wrapped objects
as errors.

Change-Id: I4d7ee0d7475174c20a18df99ebda7ef1a3afbd56
2021-01-08 17:13:13 +01:00
jenkins-bot
7e3c1e6629 Merge "ApiQueryInfo: Return watchlist expiry when applicable for inprop=watched" 2021-01-08 07:52:13 +00:00
jenkins-bot
a34e301357 Merge "ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase" 2021-01-08 05:42:37 +00:00
C. Scott Ananian
665eae14ac ParserTestRunner: share more code w/ MediaWikiIntegrationTestCase
Refactor the database setup code to share more code between
ParserTestRunner and MediaWikiIntegrationTestCase.  Made
`::setupAllTestDBs` static so it can be reused from
ParserTestRunner.

Made ParserTestRunner::addArticle more like
MediaWikiIntegrationTestCase::addCoreDBData().  Some additional
refactoring work could be done here in the future to share more code.

After the refactoring the ParserTestTables hook is no longer necessary
and so has been (soft) deprecated.  MediaWikiIntegrationTestCase
clones all database tables, so ParserTestRunner no longer needs to ask
extensions for a list of specific tables it should clone.  Cleaning up
the handful of extensions which define this hook will be left to a
future patch set.

Change-Id: I5124789fac333a664b73b4b4a1e801ecc0a618ca
2021-01-07 23:31:12 -05:00
jenkins-bot
e00dc65892 Merge "exception: Move remaiming MWExceptionHandler tests to its test case" 2021-01-08 01:21:00 +00:00