Commit graph

1774 commits

Author SHA1 Message Date
Timo Tijhof
6cf36e5ddd mediawiki.action.edit: Fold watchlistExpiry.js into this module
Bug: T274688
Change-Id: Ieaac857a201eaa6d4fb2d7a910ccf45d1792fcf6
2021-02-12 23:56:27 +00:00
jenkins-bot
5da524fe02 Merge "Safe-guard switch possibly doing bad comparisons" 2021-02-10 21:46:39 +00:00
jenkins-bot
264f4d6947 Merge "Revert "Do not return internal edit status from EditPage"" 2021-02-10 21:46:32 +00:00
Thiemo Kreuz
ca56a3a1b8 Safe-guard switch possibly doing bad comparisons
Old PHP versions are fine doing a `switch` with anything, even
if the types don't match. This changed. More recent PHP versions
start to bring up notices and such when a `switch` accidentially
compares e.g. an object with an int.

Bug: T255177
Bug: T258790
Change-Id: Ib415bd2fb394b95b02737b6df50e4e1fbbc440d3
2021-02-10 19:42:25 +01:00
Umherirrender
9d77064647 Skip div with mw-edit-longpage-hint when it is empty
Empty div can affect styleing of the page

Change-Id: I2cef09e92ebdb74488add82df9dfa51e07d7f4b6
2021-01-19 23:08:31 +01:00
Thiemo Kreuz (WMDE)
331b39eb64 Revert "Do not return internal edit status from EditPage"
This reverts commit 8fd8fb47b3.

Bug: T258790
Change-Id: I7e7d6ca38e86295b2fe8a7b0883d02caccf815d7
2021-01-15 16:24:10 +00:00
jenkins-bot
afc51ddd42 Merge "Make sure, that "Prompt me when entering a blank edit summary" works with Hooks" 2021-01-06 17:17:40 +00:00
Florian
319f9a7e40 Make sure, that "Prompt me when entering a blank edit summary" works with Hooks
Currently, if an extension aborts the save of an edit (e.g.
ConfirmEdit or AbuseFilter), they add a message to resubmit the form
(e.g. with the correct CAPTCHA or after reading an information
message). In this case, and in case that the user activated the
"Prompt me when entering a blank edit summary" option, MediaWiki will
ask to provide an edit summary or re-submit the form to save the edit
without a summary. After clicking submit again, an extension maybe
aborts the edit again (for the same reason as for the first time), and
the user need to re-submit the form again. After the submit, MediaWiki
will ask for the edit summary again. The user only sees this loop.

The cause is, that MediaWiki doesn't know, that the edit summary
warning was acknowledged by the user already. This commit changes how
the wpIgnoreBlankSummary hidden field is added to the form output. It
now is added, if the wpIgnoreBlankSummary form field was already set
in the request. This is only the case, if the user already clicked the
save button again (after seeing the edit notice).

Bug: T12729
Change-Id: I53a6cf277f77e033d4b75e64731fd37b46c3926e
2021-01-04 21:16:03 +01:00
James D. Forrester
abdc94a3da Swap out uses of User->isLoggedIn() with ->isRegistered()
Bug: T270450
Change-Id: I90ff94a553ebae9a4ef97c25c333f067f19c327d
2020-12-22 03:13:37 +00:00
DannyS712
c711960e3f SECURITY: Act like users don't exist if hidden from viewer
When viewing Special:Contributions for a hidden user and
a missing user, or the user page of a hidden user and a
missing user, if the viewer cannot see hidden users
the output should be the same for hidden users and
missing users.

To that end
* In EditPage.php, for users that exist but are hidden from the
  viewer, do show `userpage-userdoesnotexist` and do not show
  an excerpt from the block log.

Bug: T120883
Change-Id: Ife272a0eb1f3322bc8eb30ca803bd21801acba3e
2020-12-18 00:35:19 +00:00
jenkins-bot
2b53f3f92f Merge "mw-warning class is replaced with warningbox" 2020-12-10 17:15:25 +00:00
jenkins-bot
90f5a6f73c Merge "EditPage::internalAttemptSave - run onEditFilter hook earlier" 2020-12-09 23:11:20 +00:00
jenkins-bot
36b0104de4 Merge "Add EditPage::handleFailedConstraint" 2020-12-09 23:11:12 +00:00
jenkins-bot
7611c85594 Merge "ImageRedirectConstraint: accept Content objects" 2020-12-09 22:46:44 +00:00
DannyS712
20c3d9f5fc EditPage::internalAttemptSave - run onEditFilter hook earlier
The conversion of text to a content object will be part of the
eventual backend, while the hook running won't be - flip
the order to make eventual migration easier

Bug: T157658
Change-Id: I9b3a8c5380b76b565be339ccf33537545150c352
2020-12-09 22:33:22 +00:00
DannyS712
d39e3c8fa2 Add EditPage::handleFailedConstraint
Bug: T157658
Change-Id: I8938c08ce1f7abc2f4c5ae3cb52695c084f6ad2f
2020-12-09 22:16:59 +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
jdlrobson
ddb0c53f46 mw-warning class is replaced with warningbox
The styles can be removed as there are no caching implications here
If a skin is loading `legacy` feature or providing its own (e.g
Minerva)

Non-Wikimedia skins loading content but not legacy will lose
styling here, but that will be consistent with other message
boxes in the interface.

Bug: T269797
Change-Id: I5cfa9d83bedd2786d65d835c1f7623b7a61317c4
2020-12-09 13:27:52 -08:00
DannyS712
458796f7ee Emit deprecation warnings for internal EditPage fields
Bug: T252907
Change-Id: I9f0388f1a72bd3253210f8fed2c36a26824a8fde
2020-12-09 20:23:52 +00:00
DannyS712
579bf9bfe1 EditPage: cleanup mergeChangesIntoContent
Avoid modifying $editContent passed by reference,
in preparation for moving the method to the EditManager backend

Bug: T157658
Change-Id: I413c9896a9a3e57c3ffe11d071ff9bf2b57679f8
2020-12-02 04:35:12 +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
c02ba2a6d0 EditPage: use TextFormatter in ::newSectionSummary()
So that, once the method is moved to the EditManager, a
request context is no longer needed

Bug: T157658
Change-Id: I2076458dd92c7ea12dba9e7a4d75e60355a05e6a
2020-12-01 20:43:27 +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
5ec0364463 EditPage: misc cleanup related to eventual backend
Add some to-do comments, reorganize some code, should be a no-op
Most notably:
- ::newSectionSummary() now returns an array instead of "returning"
  the anchor for the new section by modifying a parameter passed by reference

Bug: T157658
Change-Id: I88bce764d04140653cc847185a823d79ff555bb5
2020-12-01 15:48:06 +00:00
Cormac Parle
78e556f67b Show read-only wikitext if editing old revision with non-main-slot diffs from latest
Bug: T225897
Change-Id: If2b3ce77dc6e1427bcbaa35ebc33eaba047322d8
2020-11-20 17:42:54 +00:00
jenkins-bot
5d4b38f0fc Merge "Reduce public methods of EditPage" 2020-11-18 03:58:36 +00:00
DannyS712
f14c2cb8ef Add AccidentalRecreationConstraint
Bug: T157658
Change-Id: Ia9346ceb06ca060cd6e953b1d5b358aabc853eb3
2020-11-16 22:36:54 +00:00
DannyS712
5654c9559a Reduce public methods of EditPage
Make private the methods only needed
in the class (and tests), no need for deprecation
because they are not used in any extension per
codesearch. Remove EditPage::setPreloadedContent
entirely, since it is unused.

Bug: T252907
Change-Id: Id47421e01da51d57842390682ace2c33eec3b467
2020-11-16 22:21:59 +00:00
jenkins-bot
342cee8f80 Merge "Replace deprecated WikiPage::factory in EditPage" 2020-11-12 22:12:05 +00:00
DannyS712
f10795c3cd EditPage: Add two more constraints
- AutoSummaryMissingSummaryConstraint
- SelfRedirectConstraint

Bug: T157658
Change-Id: I0bc29d81ec3df6228a04f41df66b53b113792e38
2020-11-11 23:15:42 +00:00
Umherirrender
d165f7fbff Replace deprecated WikiPage::factory in EditPage
Change-Id: Ica08eb98ab382fca2a9917a935acd1f8a7356d31
2020-11-11 22:52:45 +01:00
jenkins-bot
2d9b7a99e2 Merge "EditPage: Move $sectionHeadingToCheck handling to SpamRegexConstraint" 2020-11-11 02:20:08 +00:00
jenkins-bot
7edcf42b45 Merge "EditPage::getCurrentContent - $content is never false" 2020-11-11 02:18:40 +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
20506709e1 EditPage::getCurrentContent - $content is never false
If there is no revision, it is set to null, otherwise it is
the result of RevisionRecord::getContent, which is
either a Content object or null

Bug: T251023
Change-Id: I03255fc453e1d7437e5d701b098cddca21816fda
2020-11-10 23:57:23 +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
a6610c7e52 EditPage::getCurrentContent don't change $currentModel or $currentFormat
Bug: T251023
Change-Id: I26878abe5c795d0dacea4eeaf49d042eafb45d6c
2020-11-09 02:40:58 +00:00
DannyS712
35bc74bea9 EditPage::runPostMergeFilters never starts with a hook error
EditPage::runPostMergeFilters used to run two hooks,
EditFilterMerged and EditFilterMergedContent, and checked
for a hook error after each. When the EditFilterMergedContent
hook was removed in 99800a9e03,
the check for a hook error created as a result of running that
hook was not removed.

Additionally, the hook error is already checked elsewhere
before the method is called.

Bug: T157658
Change-Id: I6704906c2abda2602f9994121f7cbd7c8a059eea
2020-11-07 01:13:44 +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
Ammar Abdulhamid
f433cd6958 Replace deprecated Title::isDeletedQuick()
Bug: T261880
Change-Id: Iec7278759accde4372a3230c7e122269d163365c
2020-11-03 10:32:17 +00:00
DannyS712
cc8bab4111 Add PageSizeConstraint and ChangeTagsConstraint
Bug: T157658
Change-Id: I2c7b4f77cd07c72b42eaeb7e37095461c92b367a
2020-10-28 16:03:02 +00:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
DannyS712
4d1bc98bcc Reorder some of the code in EditPage::internalAttemptSave
Simplifies the use of constraints - only use a single
Runner.

Should be a net no-op in terms of whether an edit is
allowed or not, but the error code returned may change
if multiple constraints would have failed and a different
one is now checked first.

Bug: T157658
Change-Id: Ia8745eb06e96bd89e735fe64b2f9fdfcf5d0f917
2020-10-26 23:07:37 +00:00
DannyS712
05ae763ba2 EditPage: Migrate more checks to constraint
Add
- ContentModelChangeConstraint
- EditRightConstraint
- ImageRedirectConstraint
- ReadOnlyConstraint
- UserBlockConstraint
- UserRateLimitConstraint

Additionally:
- Split EditPageTest into a separate file for
all of the constraints being tested

- Add a helper EditConstraintTestTrait

- Add debug logging for EditConstraintRunner for
the result of each constraint

- Changed the order of some of the checks, which
may result in a different failure code if multiple
checks were going to fail, but shouldn't change the
overall result of whether an edit fails or not.

Bug: T157658
Change-Id: Ib8f8b62b9928544e5559c96d82bf850dd8cf9b05
2020-10-26 22:01:05 +00:00
DannyS712
7ed8a02a57 Reorder some of the checks in EditPage
Will make moving to constraints easier
Should be a net no-op, at most some failures
will result in different error messages based
on which check comes first

Bug: T157658
Change-Id: I1adb6e0f88c5c460a9cfdaff9a094da4e485953e
2020-10-22 00:26:29 +00:00
DannyS712
e50dacf78c EditPage: Move spam checks to SpamRegexConstraint
Bug: T157658
Change-Id: I06ef5796f9da7b0e8555768ec6fd128b4f778294
2020-10-21 22:43:01 +00:00
DannyS712
c4e8103a36 EditPage: add EditConflict log channel
Rather than using wfDebug, retrieve a
dedicated logger, so that it can eventually
be injected

Additionally, normalize the messages
using context instead of concatenating
the variables.

Bug: T157658
Change-Id: Ie8f5d503e0e872e017b37f6849ead2abbd0e1176
2020-10-21 17:09:50 +00:00
DannyS712
dc32b15d8d Add EditConstraintFactory, migrate SimpleAntiSpamConstraint
Factory is a service in ServiceWiring, given the number
of dependencies that will eventually be needed, but is
internal and has no corresponding method in MediaWikiServices

Bug: T157658
Change-Id: I801a09f5133bed14da10c64a42ca0658024357d3
2020-10-21 14:36:01 +00:00
DannyS712
1aa3a1395c Introduce EditConstraint system, migrate unicode check to constraint
This is the start of "Phase 1" of the migration described in
T157658#6191234. For now, only a single constraint, the
requirement that EditPage::$unicodeCheck match the expected
value, is moved to the new system, in the UnicodeConstraint class.

Both the EditConstraintRunner and the new UnicodeConstraint
have 100% test coverage with pure unit tests.

Bug: T157658
Change-Id: I4fc806ec0fd631e265948a59244295eebec691fa
2020-10-20 14:09:26 +00:00