Commit graph

103 commits

Author SHA1 Message Date
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
Bartosz Dziewoński
6a20dc29ae editpage: Split off producing edit intro messages and preloaded content
Introduce two new classes, containing code split off from EditPage:
* IntroMessageBuilder (edit notices and other intro messages)
* PreloadedContentBuilder (initial text of new pages / sections)

I'm doing both of these features in one change, because they share a
lot of code. They are meant to be used by alternative editors to
support all of the features of the MediaWiki edit form. This isn't
everything you need yet (we should at least do this for the edit
checkboxes too), but it's a step.

Bug: T201613
Change-Id: If0b05710cb52a977bf4e85947d72d68683a0a29e
2023-05-16 20:51:00 +02:00
Bartosz Dziewoński
d0f2aaf890 EditPage: Pass current value of 'wpWatchlistExpiry' like other fields
This is to allow moving getCheckboxesDefinition() to another class.
Also improve documentation.

Change-Id: I6463f74a4047b83942773ef4d62508c58bb5e26c
2023-04-20 18:11:53 +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
Jon Robson
37bd453af6 EditPage: Add capability of targeting editors of code in editor
Can also be used by projects for a policy/recommendations/
to advertise gadget community.

Bug: T311891
Change-Id: Ieee508409843561481da246cf26e0f1d93fea6ed
2023-03-23 17:31:47 +00:00
Jon Robson
599a2d796c Make messages about editing site code more prominent
It should be clearer that these pages have special capabilities
than it is currently.

Bug: T311891
Change-Id: Id2114a65635c050a2017926274622f0a3c2d58d6
2023-03-16 19:07:29 +00:00
Timo Tijhof
39ead04e98 objectcache: Remove $wgMainWANCache and $wgWANObjectCaches
We always wrap the local cluster cache, and there are no subclasses
of WANObjectCache. It was never documented or recommended how these
would be used. It is a left-over from the original 2015 Multi-DC plan
in which WANObjectCache would work differently. See task for details.

Note that this requires no configuration changes, even in the
theoretical case of these variables being used, as the only
option is to use the main cache, and that's also the default.

* Update WAN overrides to override the underlying main cache
  instead.
* Fix EditPageTest which was previously implicitly using a 'hash'
  as main cache but also relying on wan cache to be 'none'.
  The part that it actually needs is the 'none'. When WAN cache is
  enabled, testUpdateNoMinor fails due to an edit conflict because
  one of the edits it makes is made with a current timestamp whereas
  it expects to simulate wpEdittime in the year 2012 which, when
  caching is enabled, is ignored and becomes the current time instead.
  I don't understand exactly why, but I'm going to conserve that
  behaviour for now.
* Fix TemplateCategoriesTest, which was failing due to an unexpected
  cache hit:
  > [objectcache] fetchOrRegenerate(…:page:10:…): volatile hit
  This could be solved in a more realistic way by splitting the test,
  or by explicitly resetting services half-way the test to clear
  WikiPageFactory, PageStore and WANCache process state.
  For now, keep the prior behaviour of no cache in this test.

Bug: T305093
Bug: T329680
Depends-On: If890622eed0d0f8b4bd73d36ba1815a3d760ea05
Depends-On: Ie1def75208822bdf19bb2cfd7e6edf32c2000e6b
Depends-On: I35cce61dc3ee90dcee3dd6f0b36f84133be029ed
Change-Id: I53781a8c06ebb2583f6ca83dd91bbfe8a5c88b13
2023-03-07 22:47:04 +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
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Tim Starling
43a93d9782 Use the null coalescing assignment operator
Available since PHP 7.4.

Automated search, manual replacement.

Change-Id: Ibb163141526e799bff08cfeb4037b52144bb39fa
2022-10-21 13:26:49 +11:00
jenkins-bot
aafa2e0b04 Merge "tests: Replace deprecated WikiPage::factory" 2022-09-09 16:25:08 +00:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
NovemLinguae
aad407bb3e Add "1 year" to watchlist expiry
When $wgWatchlistExpiry = true and a user adds a page to their
watchlist, they are currently presented with a combo box where they can
pick a duration of permanent, 1 week, 1 month, 3 months, and 6 months.

This patch adds 1 year to the combo box, and raises the maximum age to 1
year. `api.php?action=watch&expiry=1 year` will now also work.

Bug: T313255
Change-Id: Ia84d6f99584ae23feea3831499d5baee2dd1a024
2022-08-13 00:50:05 -04:00
Derick Alangi
9899846d10
tests: Use overrideConfigValue(s) where necessary
The files in `tests/phpunit/includes/` directory are now all
covered. Will do sub-directories of `/includes/` next.

Change-Id: I8d5655ce267b6d32cf3c7ee40dc5d2992631b5a6
2022-07-16 23:45:52 +01:00
Bartosz Dziewoński
252a1c8e5f Language: Inject NamespaceInfo
Change-Id: I90eee60467698bbefb619bfa69abfaa10c759fea
2022-05-11 17:24:17 +02: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
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
Daimona Eaytoy
2688c59606 tests: Replace usages of deprecated WikiPage::doDeleteArticleReal
Add a new helper to MediaWikiIntegrationTestCase, since deleting pages
seems to be pretty common in tests.

Some calls to WikiPage::factory were also updated to use WikiPageFactory.

Change-Id: I5b5100273a00ac292a1900022ca79708fa254347
2022-01-17 15:38:02 +00:00
Reedy
8c39aab84b Remove or replace usages of "sanity"
Bug: T254646
Change-Id: Ib192dc5704a14d02c7c374d0ab29bac55c5df24a
2021-11-21 19:35:49 +00:00
jenkins-bot
8ee86f1734 Merge "Avoid using ContentHandler::getContentText()" 2021-09-20 19:14:10 +00:00
Alexander Vorwerk
c4b2765ebd Avoid using ContentHandler::getContentText()
ContentHandler::getContentText() is deprecated and should be
replaced with Content::getText() for TextContent instances.

Change-Id: I556d3d3f64fafd1d54c4a0c5021efaff2d9c3ce8
2021-09-20 15:32:44 +02:00
daniel
6ce0d2c825 Make EditPage use PageUpdater
This ensures that a DerivedPageDataUpdater is initialized earlier during
the edit process, so it can be used by hooks to access the state of the
ongoing edit.

This patch also cleans up PageUpdater a bit to make the internal information
flow more consistent with the idea that PageUpdater is acting as a
builder for a new revision.

Change-Id: I99abb7bdffb2b5ff5979ba5b1e56d39dba4cd3dc
2021-09-16 13:11:15 -07:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
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
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
Tim Starling
7430e278c6 EditPage::getExpectedParentRevision(): guard against null edittime
Document the fact that EditPage::$edittime can be null, and guard
against a type mismatch error in getExpectedParentRevision() which is
hit if EditPage::$edittime is null and EditPage::$editRevId is a value
that is false when converted to boolean.

Bug: T277204
Change-Id: Ibc9500a314ddfd99452d6c03d8906f69cdebc0e4
2021-05-06 11:38:30 +10:00
DannyS712
7bd7d2a6c1 Remove hooks that use Revision objects
All hooks were previously hard deprecated
in 1.35. Affected hooks:
* ArticleRevisionUndeleted - use RevisionUndeleted
* ArticleRollbackComplete - use RollbackComplete
* DiffRevisionTools - use DiffTools
* DiffViewHeader - use DifferenceEngineViewHeader
* HistoryRevisionTools - use HistoryTools
* NewRevisionFromEditComplete - use RevisionFromEditComplete
* PageContentInsertComplete - use PageSaveComplete
* PageContentSaveComplete - use PageSaveComplete
* ParserFetchTemplate - use BeforeParserFetchTemplateRevisionRecord
* RevisionInsertComplete - use RevisionRecordInserted
* TitleMoveComplete - use PageMoveComplete
* TitleMoveCompleting - use PageMoveCompleting
* UndeleteShowRevision - no replacement

Includes a fix for setting the associated rev id
of page protections, which previously was only done
using $nullRevision which was a Revision object created
if any hooks needed it; those hooks were hard deprecated
and so for WMF prod the rev id was not being set.

Bug: T247143
Depends-On: Idfa345193ae99fb2f1c9a8f8d28d8d540a6e3d62
Change-Id: I519167f76a5a3c1f5410415b2721462a3dcc3ec8
2021-04-30 17:28:20 +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
Cindy Cicalese
fb6b6e058c Fix parameter order of setWatch to match add/removeWatch
Change-Id: I0ea63482a5cab24c23b49b8bbe6c80bdbe8b102b
2021-04-21 04:41:38 +00:00
Cindy Cicalese
a384acffa7 Use WatchlistManager in several classes
Change-Id: I720629e08373736b5fc1e12563b5059311b113e1
2021-04-21 00:37:40 -04:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +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
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
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
e50dacf78c EditPage: Move spam checks to SpamRegexConstraint
Bug: T157658
Change-Id: I06ef5796f9da7b0e8555768ec6fd128b4f778294
2020-10-21 22:43:01 +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
115635d743 EditPageTest: No need to set $wgUser
Bug: T243708
Change-Id: Ibf5d955891aebb1519edd5394bcd02de373bbaa1
2020-09-15 21:26:07 +00:00
DannyS712
5cf9ac0073 Reduce use of $wgUser in EditPageTest
Rather than reading from $GLOBALS for
individual tests, set the user to a test user

Keep writing to $wgUser via setMwGlobals
for now.

Bug: T243708
Change-Id: I8935c18f4a0bda704eaf752683ab7f510f1ed3cb
2020-09-13 23:33:43 +00:00
jenkins-bot
1b1d8d9589 Merge "Disable section editing on non-current revision." 2020-09-09 16:09:22 +00:00
Sam Wilson
3b71d54bc4 Check existing watchitem when saving action=watch
When watching via action=watch, there's no need to
save if nothing has changed. This is already how
EditPage does it (by calling WatchAction::doWatchOrUnwatch())
so this change emulates that and also calls
doWatchOrUnwatch() when saving the watch item.

The format that's used in the expiry dropdown (in action=edit
and action=watch) is also changed to ISO8601 so that it
includes a timezone specifier and removes any ambiguity about
what timezone it is in.

The minor change to $changingWatchStatus is just to keep it as
a boolean and not turn it into an int.

Bug: T260009
Change-Id: If94ea7394588646abdac9a5025b0c8903366b521
2020-09-09 14:39:07 +08:00
Ammar Abdulhamid
bf55265e6b Disable section editing on non-current revision.
Production error reported in T161199 was caused because of some bug on
how section edit support is checked in EditPage.

When we attemt to edit a section of any page; isSectionEditSupported()
method is called to check whether the content model allows that. If it
doesn't, an ErrorPageError is thrown and that's the end. However, the
method flaw is that it only checks the content model of the page's title
which is equivalent to the model of the latest revision.

But ealier page revisions now may contain different content models from
the latest revision.

If a page's current CM ALLOWS section edit and one of its older revisions
has a CM that does NOT ALLOW section edit, attempting to edit any section
of that old revision will lead to a call to the isSectionEditSupported(),
which will now return incorrect truthy result based on the current page's
content model that allows section edit.

This will lead to a call to getOriginalContent() which returns content of
the revision. Attempting to extract content of a section from that will
return null and the null is retained as the return value of getContentObject().

Since the old revision and current revision have different CMs edit will
not be llowed, to explain this,  a call will be made to displayViewSourcePage()
method which is typehinted to require Content as the as its first argument.

So because of the bug null will be given to displayViewSourcePage() instead of
Content and that will lead to the TypeError that was reported in T161199.

The initial and simple solution to this bug is to just fix the method to ensure that
it checks both content models of the title and the relevant fetched revision
which will ensure correct result for section edit support is returned.

But later it was pointed out by Anomie that editing section  of oldrevision
is not something that was intentinally designed to be so. In fact it was
disallowed from the UI because of its consequence, but it was not enforced
technically.  Task T251680 was created to explain this in more depth.

This patch;
* Section edit support is changed to require, in addition to the content
model allowing so, that the revision to be edited be current revision.
* Section editing on non-current revision is already superficially
disallowed as there's UI button to reach that patch. Even the  initial
reported bug couldn't have happened or be reproduced any UI means except
by directly playing with the URL
* This will automatically resolve the original bug that led to the error and
enforce what has been already disallowed.

Bug: T251680
Bug: T161199
Change-Id: I05ca6ac90509deec51bf38ec98e9aef169d87459
2020-09-08 23:07:00 +00:00
DannyS712
0637d80572 Hard deprecate the rest of the Revision class
Bug: T246284
Change-Id: I126d7892c90aa2200c668b5717820e729613bed8
2020-07-02 09:02:02 +00:00
jenkins-bot
7701131a76 Merge "Add watchlist expiry to edit form" 2020-07-01 20:32:26 +00:00
DannyS712
52051a996b Hard deprecate the TitleMoveComplete and PageContent(Insert|Save)Complete hooks
Bug: T250023
Bug: T250566
Change-Id: I7e701e0aac0b09acae448df3a7c72f2047bc2118
2020-07-01 00:22:56 +00:00