Commit graph

58 commits

Author SHA1 Message Date
DannyS712
4c934d383f Move section-check logic to ExistingSectionEditConstraint
Instead of conditionally adding it, move the check for the section being new or
not into the constraint, to reduce the logic needed in
EditPage::internalAttemptSave().

Bug: T157658
Change-Id: If16f5a097dd38c5206f748fa4fb8dc6e56cf09cb
2024-07-12 21:46:37 +00:00
DannyS712
f122838aba Move AS_REVISION_WAS_DELETED handling into constraint
Use the renamed ExistingSectionEditConstraint, and just make the content it
gets nullable.

Bug: T157658
Change-Id: I6e077f1e54ea05f77b431a7437c4a56c9dc56306
2024-07-12 21:21:28 +00:00
DannyS712
8ae5a07948 Rename AutoSummaryMissingSummaryConstraint
In preparation for also handling the AS_REVISION_WAS_DELETED failure in the
constraint, rename it in a separate commit so that git can more easily track
the change.

Bug: T157658
Change-Id: Id55b40d8e327429fbaf45a96c0b00caaa9110da1
2024-07-12 21:04:32 +00:00
DannyS712
72205f3c41 EditPage::internalAttemptSave() - move more logic to constraints
Instead of conditionally adding the NewSectionMissingSubjectConstraint and
MissingCommentConstraint based on creating a new section, always add those and
have the constraints themselves just pass if not creating a new section

Bug: T157658
Change-Id: Ie5bf352bd714b6b706445f4f02c986706f26bb1f
2024-07-11 21:35:48 +00:00
Bartosz Dziewoński
3d92cb2f82 Replace some uses of deprecated PermissionManager::getPermissionErrors()
getPermissionStatus() does the same thing but better.

A lot of things use the legacy error arrays though, we're nowhere near
removing it.

Change-Id: Iff60dbb0593329a584d003b2407bbf24d5b22aea
2024-06-27 18:14:28 +00:00
Umherirrender
f27c2433bb tests: Use namespaced classes (2)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I4ff4d0c10820dc2a3b8419b4115fadf81a76f7a2
2024-06-13 23:21:02 +02:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Daimona Eaytoy
c8e2f99211 Update tests for PHPUnit 9.6 (part 2)
- Avoid withConsecutive()

Bug: T342110
Change-Id: Iedda49765cbceeb10ccd72d0248f3cda9241da1e
2024-01-17 18:16:38 +01:00
Daimona Eaytoy
605d12b9b3 Update tests for PHPUnit 9.6 (part 1)
- Avoid defining abstract test classes (ending in "Test")
- Avoid withConsecutive()
- Avoid getMockClass()

Bug: T342110
Change-Id: I131e0d85bd14e75aaebd6f212b2e64a45d4c73a2
2024-01-16 23:36:15 +01:00
daniel
afbad85185 EditPage: replace usage of User::pingLimiter
Using RateLimiter::limit instead.

Change-Id: Ia27cba5023994bfdc61f6d27702eeb98502d6dd4
2024-01-02 20:14:12 +01:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Brian Wolff
d3f38054a9 Change EditPage 'edit' rights check to do per page instead of general
Previously the edit rights check would fail if you didn't have edit
rights in general. This made it difficult to write custom permission
extensions that want to give users edit rights to a few specific pages
while not giving rights in general.

This check goes back to 2005 when the edit rights system was first
introduced a2a28a34c1. Presumably per-page permissions didn't exist
yet.

Bug: T342515
Change-Id: Ibcf0e18c44912abdd02a676a551da3cc7ed22ee0
2023-11-04 21:46:03 +06:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Func
4d1da6f7f8 phpunit: Update @covers annotations for namespaced classes
We renamed many classes to be namespaced, but the `@covers` and
`@coversDefaultClass` annotations weren't updated properly.

PHPUnit didn't support short cover annotations with `use` statements,
these didn't trigger any errors yet, because they are class alias.

This patch is populated by a modified version of PhpunitAnnotationsSniff.

Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
2023-05-27 17:43:12 +08:00
Amir Sarabadani
623d3dc419 rdbms: Move ReadOnlyMode and ConfiguredReadOnlyMode to rdbms library
The db/ directory does not have an owner and it's a mess in general.
These classes don't depend on anything in core except the rdbms library.
Let's simply move it there. In other words, Krinkle made me do it.

Since the class was moved in I6202e52ba73 merged less than a week ago,
no need to alias anything.

Bug: T321882
Change-Id: I24ceeb8bf765a50f441270136acd612359d50aa2
2023-05-04 23:41:21 +02:00
Amir Sarabadani
d59ffa4202 Reorg: Move ReadOnlyMode classes to db/
They are not suitable to go to rdbms library as they depend on mediawiki
pieces, the second best place is the db/ directory.

Bug: T321882
Change-Id: I6202e52ba7306d74261206c2ba7930c5f1a0a18e
2023-04-28 12:13:01 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Amir Sarabadani
5323501d53 Reorg: Move EditPage.php to MediaWiki\EditPage
Also moving TemplatesOnThisPageFormatter to the same namesapce as it's
only used by EditPage

Bug: T321882
Change-Id: Ibefc44eb64aedb430148b109090584c3e35794ab
2023-02-15 22:40:10 +01:00
Umherirrender
167fb2a979 unit tests: Use MainConfigNames constant to refer configs
When creating ServiceOptions objects or fake HashConfigs use the
constant to refer the config name

Change-Id: I59a29f25b76e896c07e82156c6cc4494f98e64cc
2022-08-17 22:33:58 +02:00
Bartosz Dziewoński
990fd8f0b2 EditPage: Disentangle edit summary and section title
Previously, `$this->summary` was used for two different purposes.
Usually it was just the summary. But when `$this->section` was 'new',
then it was actually the section title most of the time – unless
`$this->sectiontitle` was also set (in which case it took priority),
and until it was replaced by the real edit summary (near the end of
the processing, after copying the section title to the page content
and before saving changes).

Unsurprisingly some of the code didn't handle this duality correctly,
causing T191722 and T311533.

Now `$this->summary` is always the summary, and when `$this->section`
is 'new', then `$this->sectiontitle` is always the new section title.

The only place where this duality remains is in the input attributes
and query parameters, where 'wpSummary' is still used for both the
summary and the section title inputs (only one of them can appear,
depending on whether `$this->section` is 'new'). It would be an
unreasonable backwards-compatibility break to change this, and the
code handling this is somewhat isolated from the rest of the logic.

Bug: T191722
Bug: T311533
Change-Id: I5313ca9a045d112ece390b011a34192220e2abc1
2022-07-19 09:56:05 +00:00
DannyS712
ab43a98dd6 CreationPermissionConstraintTest: remove unused $title
Follow-up: I12a2f71f52a1ba7e94bf325621e62ed0e255601b
Change-Id: Idb7c9afefb2faea5da61d52fa5ff81bf1522adde
2022-06-29 23:34:57 +00:00
Daimona Eaytoy
2012fe3b2b Improve error messages in EditFilterMergedContentHookConstraint
Use multiple error boxes instead of a wikitext list of error messages,
as the latter has several issues (as reported on phab). Also, remove the
edit-error-* messages as they don't seem to add any value. Also, don't
use the passed-in context, inject what the class actually needs instead
(but keep the context for the hook).

Bug: T303060
Bug: T230229
Change-Id: I2806e57826e7ab062b45dd1d9972b05fd6baeafb
2022-03-22 14:53:02 +01:00
daniel
e239b02a5e Add convenience methods for asserting status.
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.

Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
2022-03-16 22:44:25 +01:00
Petr Pchelko
6a8a786599 Replace easy usages of User for UserIdentity/Authority
Change-Id: Id176ee0fab64707020ac6c47a087ef00f8bed4e3
2021-06-09 07:53:52 -07:00
DannyS712
bea9165e61 Tests: use UserIdentityValue instead of mock User objects
- ParserMethodsTest for creating ParserOptions
- SimpleAntiSpamConstraintTest

Change-Id: I5f8ffbee5ee1ff8e08cae7e6ace30ff7b186539c
2021-05-03 15:41:48 +00:00
Kunal Mehta
ec0be22116 Update Legoktm's email address
Change-Id: Icd58c93bb0cff5b0a4e7b7f02873a271bab8964f
2021-05-02 05:39:37 +00:00
jenkins-bot
89b00fcfbe Merge "Remove unnecessary ->equalTo() from tests" 2021-04-23 14:43:04 +00:00
Thiemo Kreuz
c1ee8250e9 Remove unnecessary ->equalTo() from tests
This is the default anyway when using ->with(). The test code
becomes so much more readable without this, I would like to
argue. Let it just say "with these values".

Because of the way I split my changes into multiple patches
there are a few other changes in this patch I could not split,
e.g. removing unnecessary ->any(). This is the default anyway
and doesn't make the test more specific.

Change-Id: I34990799fa9258ba8dc64c7e78ec43f7903b7681
2021-04-23 12:02:42 +02:00
Thiemo Kreuz
f10f4e05de Remove some meaningless $this->equalTo() from tests
This is the default behavior anyway when using ->with().

Change-Id: I64b6474280eb7da122eb22fc0afa28cca81e96c5
2021-04-22 10:47:54 +02:00
Daimona Eaytoy
535d7abf59 phpunit: Mass-replace setMethods with onlyMethods and adjust
Ended up using
  grep -Prl '\->setMethods\(' . | xargs sed -r -i 's/setMethods\(/onlyMethods\(/g'

special-casing setMethods( null ) -> onlyMethods( [] )

and then manual fix of failing test (from PS2 onwards).

Bug: T278010
Change-Id: I012dca7ae774bb430c1c44d50991ba0b633353f1
2021-04-16 20:15:00 +02:00
Func
278e195ab7 Set $status->value in EditFilterMergedContentHookConstraint::checkConstraint() properly to display error message
When hook handler return false and use $status->fatal() to put up a error,
we should set $status->value to self::AS_HOOK_ERROR_EXPECTED to show edit form
and display error message.

Bug: T273354
Change-Id: I02d643c5cb1978da8ab749856493d75137b6cb02
2021-04-15 22:01:30 +02:00
DannyS712
fb22076f1f Update creation of edit constraints following switch to Authority
No longer need the factory for many of them

Bug: T271977
Bug: T157658
Follow-up: I12a2f71f52a1ba7e94bf325621e62ed0e255601b
Change-Id: I5019ea46bccb1f23643424c2798061a25eb3f623
2021-03-22 23:11:46 +00:00
Petr Pchelko
595d605e34 Convert EditConstraints to Authority
Bug: T271977
Change-Id: I12a2f71f52a1ba7e94bf325621e62ed0e255601b
2021-03-03 17:12:07 -07:00
DannyS712
008e09f766 Split TextboxBuilderTest into separate unit tests
Change-Id: I7faa32e6ab6c318cef9ede274096aecd2ec76cac
2021-03-01 18:26:46 +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
jenkins-bot
12e73d4beb Merge "Add tests for EditConstraintFactory" 2020-12-26 20:27:30 +00:00
DannyS712
7ef44935d8 Add tests for EditConstraintFactory
Bug: T157658
Change-Id: I175afe4d1217f9e57aaa8e8d8f93c70736dac801
2020-12-26 03:30:57 +00:00
DannyS712
e8b332eadb Bring SpamRegexConstraint test coverage to 100%
Bug: T157658
Change-Id: I89d08059937d2a84de0cbc53fd4ac56153018e40
2020-12-26 03:11:55 +00:00
DannyS712
c4b1396e0d ImageRedirectConstraint: accept Content objects
More common interface for constraints

Bug: T157658
Change-Id: Ia50c3fb647ed803a69f5e4511047f1ab88e43bf7
2020-12-09 21:41:13 +00:00
DannyS712
f75f3c75ea UserRateLimitConstraint: move detection of content model change to constraint
A step towards a more common interface between the different
constraints, detect whether the content model changes within the
UserRateLimitConstraint rather than relying on EditPage to inject
the answer

Bug: T157658
Change-Id: Ifa35cbabe74df458784a10b3d2815a1e8e7dcdf8
2020-12-01 23:08:47 +00:00
DannyS712
883199bc98 Move more logic into edit constraints
Specifically, remove the conditional processing of
ContentModelChangeConstraint and ChangeTagsConstraint in
favor of early returns within the constraints

Bug: T157658
Change-Id: I377c0e3d9611d2da0a2d0f9bca055d65a1bec7e6
2020-12-01 18:44:03 +00:00
DannyS712
f14c2cb8ef Add AccidentalRecreationConstraint
Bug: T157658
Change-Id: Ia9346ceb06ca060cd6e953b1d5b358aabc853eb3
2020-11-16 22:36:54 +00:00
DannyS712
f10795c3cd EditPage: Add two more constraints
- AutoSummaryMissingSummaryConstraint
- SelfRedirectConstraint

Bug: T157658
Change-Id: I0bc29d81ec3df6228a04f41df66b53b113792e38
2020-11-11 23:15:42 +00:00
jenkins-bot
2d9b7a99e2 Merge "EditPage: Move $sectionHeadingToCheck handling to SpamRegexConstraint" 2020-11-11 02:20:08 +00:00
DannyS712
1f05a9799b EditPage: Move $sectionHeadingToCheck handling to SpamRegexConstraint
Cleaner and simpler if the constraint takes care of determining
how to handle the section title

Bug: T157658
Change-Id: I45de1aca77fe1ddcd3d94b6ca964328d9911b440
2020-11-11 00:51:58 +00:00
DannyS712
3b0c5e579b Move EditPage::runPostMergeFilters to a constraint
Bug: T157658
Change-Id: I071163d6d2538948693527c36e8e59281f528402
2020-11-10 23:34:20 +00:00
DannyS712
d7a737fca9 Rename MissingSummaryConstraint to NewSectionMissingSummaryConstraint
There is another place a missing summary is
checked, with different parameters and under
different conditions

Bug: T157658
Change-Id: I988a34a2a130244e6e250259b66727ef979a91ec
2020-11-09 22:59:20 +00:00
DannyS712
44418378e0 EditPage: Factor out more constraints
CreationPermissionConstraint
DefaultTextConstraint
MissingCommentConstraint
MissingSummaryConstraint

Bug: T157658
Change-Id: I55cf336ff6dfb990045e43e6dcd7437a241a46b2
2020-11-04 21:29:54 +00:00