Commit graph

1868 commits

Author SHA1 Message Date
Bartosz Dziewoński
c2e4014a93 EditPage: Deprecate using getCopyrightWarning() without passing context
Follow-up to I5f7c77970d0525c0ff394f8bd72c69dcb5d00623.

Depends-On: Iaa626f0e6379a5a370f9c465cea8528bb5bde7f7
Depends-On: I160ad1e16d3988a8a1f9a703b5241ddc1e6f9177
Change-Id: I1b4cdc1abfd538df60bea89a1e7d810ee83f5ca2
2022-03-01 00:26:17 +00:00
Umherirrender
b126dbe3f2 Fix various documentation related to null types
The functions returning null or the class property is set explict null

Found by phan strict checks

Change-Id: I4a271093fb6526564d8083a08249c64cb21f2453
2022-02-26 10:31:24 +01:00
Niklas Laxström
94ab2e6ac4 EditPage: Support Special:MyLanguage for preload param
This allows nonexistent translated pages to fall back to the
corresponding page in a suitable language.

Bug: T299544
Change-Id: I278c54c682955c74bb6115a09e4a974c2b6e8ae6
2022-02-21 20:09:49 +00:00
DannyS712
e1fa59dc79 Remove public access to internal EditPage variables
Bug: T252907
Change-Id: Id349a57620439297a288a7fb3b56301bf2a030fc
2022-02-18 15:08:52 +00:00
Alexander Vorwerk
a6b835c98a Add @deprecated to EditPage::getCopywarn()
got deprecated in I4d515744f337bec6da8ca2ef43efa99f0c8cb974

Change-Id: I9615e38602d2b8194a1e254f09864fa2986ac5f6
2022-02-16 22:27:35 +01:00
Bartosz Dziewoński
e304c15856 EditPage: Parse wikitext in the usual way in the copyright message
Rather than pass around wikitext, just use Message::parse().
We already call this method this way in VisualEditor.

Bug: T301890
Change-Id: I4d515744f337bec6da8ca2ef43efa99f0c8cb974
2022-02-16 20:02:30 +01:00
Daimona Eaytoy
bd371e2e94 EditPage: misc cleanup
Mostly, use strict comparisons, and use Html:: methods instead of
building strings manually when convenient. Also add typehints to private
methods and replace a couple of deprecated things.

Also ensure that $this->section is always a string (like the
documentation claims) by setting a default in importFormData.

Change-Id: Id7c8817e55b5deb85788b1d3491f9be4d2a95874
2022-02-11 11:46:19 +00:00
Bartosz Dziewoński
858e7af980 Modernize some warnings about account not being registered
The "error" class nowadays is only supposed to be used by Parser and
related code. It renders as red text with no special formatting.
Instead use Html::warningBox(), which renders a yellow box around the
text. (Not Html::errorBox(), because these are not really errors.)

Change-Id: I7a7046bf9b9765cbb82ec3caa1530de7f05e0da4
2022-02-09 21:25:19 +00:00
Bartosz Dziewoński
524e1d612b EditPage: Allow passing context to getCopyrightWarning()
Bug: T298822
Bug: T189229
Change-Id: I5f7c77970d0525c0ff394f8bd72c69dcb5d00623
2022-01-24 23:49:27 +01:00
Bartosz Dziewoński
ea3f62d4d1 EditPage: Don't use string array keys for OOUI HorizontalLayout items
Fixes the exception "Cannot unpack array with string keys" from OOUI.
Passing associative arrays to various functions in OOUI was never
supported and now fails after OOUI v0.43.0.

Bug: T299191
Change-Id: Id2513bc610b71be16d65f2b7c0f7a73d852496cc
2022-01-14 07:30:37 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Thiemo Kreuz
5430e9cf3d Remove unused EditPage::$mPreloadContent property
Unused:
https://codesearch.wmcloud.org/search/?q=%3E(mPreload%7CsetPreloaded)(Text%7CContent)&files=%5C.php%24

There was a public setter `setPreloadedContent()` that was removed in
2020 in patch Id47421e, tracked via T252907.

The fact that the property is marked as public is most certainly not
intentional. It was introduced when `private` didn't exist. Not only
that. It was dynamically created and never declared. This was fixed
in 2011, see
https://phabricator.wikimedia.org/rMWaa9bc3ba41273f911bad6a3ac754c98e1dde229a
The assumption was made that the property was meant to be public, but
I think this was a mistake.

Bug: T297725
Change-Id: Ic6a12d706c823c31b8e8a736f078977ec64be973
2022-01-10 10:11:54 +01:00
jenkins-bot
b0049428ab Merge "Allow EditPage's preload feature only on wikitext pages" 2021-12-20 14:57:55 +00:00
Kunal Mehta
7b0c94fb0b SECURITY: Fix permissions checks in undo actions
Both traditional action=edit&undo= and the newer
action=mcrundo/action=mcrrestore endpoints suffer from a flaw that
allows for leaking entire private wikis by enumerating through revision
IDs when at least one page was publicly accessible via $wgWhitelistRead.
This is CVE-2021-44858.

05f06286f4 removed the restriction that user-supplied undo IDs belong
ot the same page, and was then copied into mcrundo. This check has been
restored by using RevisionLookup::getRevisionByTitle(), which returns
null if the revid is on a different page. This will break the workflow
outlined in T58184, but that could be restored in the future with better
access control checks.

action=mcrundo/action=restore suffer from an additional flaw that allows
for bypassing most editing restrictions. It makes no check on whether
user has the 'edit' permission or can even edit that page (page
protection, etc.). This is CVE-2021-44857.

This has been fixed by requiring the 'edit' permission to even invoke
the action (via Action::getRestriction()), as well as checking the
user's permissions to edit the specific page before saving.

The EditFilterMergedContent hook is also run against the revision before
it's saved so SpamBlacklist, AbuseFilter, etc. have a chance to review
the new page contents before saving.

Kudos to Dylsss for the identification and report.

Bug: T297322
Co-authored-by: Taavi Väänänen <hi@taavi.wtf>
Change-Id: I496093adfcf5a0e30774d452b650b751518370ce
2021-12-15 16:11:42 +00:00
Thiemo Kreuz
26087d4651 Allow EditPage's preload feature only on wikitext pages
This is a convenience feature that makes it possibly to
semi-automatically copy-paste the contents from another page when
creating a new one. The more I dig into the code, it's history and
potential use-cases the more I feel like this was never meant to be
used on non-wikitext pages.

* This feature makes it possible to trick users into making edits to
e.g. one of their personal .js subpages. I find this scary.

* "preload" and "preloadparams" are meant to work like a template
transclusion where "preload" is the name of the template. I don't
think this makes sense on non-wikitext pages.

* The feature can be used together with section=new. This doesn't
work anyway on non-wikitext pages. The only effect this patch will
have is when a non-existing page is created.

* The feature is meant to seed e.g. a new section on a talk page with
something the user can work with before it is submitted.

* But what's the point of semi-automatically seeding e.g. a .css or
.js subpage with the contents from another page? One situation I can
think of is when a new user gets the recommendation to copy-paste
another users skin modifications. It might be convenient to let
the user click a link that utilizes the preload feature instead of
manually copy-pasting code. But this comes with so many problems (e.g.
the user doesn't have a chance to understand what's going on) I don't
think it's worth it.

Bug: T297725
Change-Id: Iee2d9196854427501bf36659eace81a80a66dd26
2021-12-15 13:26:55 +01:00
jdlrobson
328ff04e0c Table of contents should not show in previews for skins that have requested not to show it
Bug: T296971
Change-Id: I1adb1451626a0bd316d54b26cbd21c2caeb0bf53
2021-12-02 14:50:53 -08:00
Derick Alangi
8fe9e0317f Introduce Redirect(Lookup&Store) services to handle redirects
The concept of a redirect chain didn't really work for a value of
max redirect > 1. In the ideal world, we just want to have a source
which points to target (source -> target) discarding the concept of
a redirect chain completely.

Having something like: source -> target -> target1 -> target2 doesn't
really work well with the current database design.

NOTE: Support for $wgMaxRedirect will be removed soon hence
deprecation without interfaces for replacement.

Bug: T290639
Change-Id: I469de6f85e405e8ddbe7abaa5b99b77cb9cf415d
2021-12-01 19:14:22 +01:00
Matěj Suchánek
50b010e5e8 Don't throw away '0' edit summary
Those "$comment ?? ''" are a bit ugly, but the other way around is
changing the return values of some ::getDescription implementations,
which is dangerous, at least.

Change-Id: I07e6b58258c256d19b058c56280150b70a46b407
2021-11-24 10:33:36 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Ppchelko
643fc535c3 Reapply "Move limit report rendering to ParserOutput"
This reverts commit 2bcb3fe567.

Reason for revert: this is a good change,
just needed more work to not break CI

Change-Id: I23768bee242e3cf81b1493a740cf070e7ad1e224
2021-11-09 11:08:08 -08:00
Ppchelko
2bcb3fe567 Revert "Move limit report rendering to ParserOutput"
This reverts commit 89028e0b8e.

Reason for revert: Temporary until we deal with T295357

Change-Id: I556de18dbf900a9bc58d5ae22d1bf194682d0840
2021-11-09 15:57:18 +00:00
Petr Pchelko
89028e0b8e Move limit report rendering to ParserOutput
This does not move the actual limit report data into
ParserOptions yet, that should be done separately
given that it will require serialization changes.
Let's get this change settled first before messing
with serialization.

This unifies canonical and non-canonical ParserOptions,
so ParserCache can now be used with both. It is hard
to say how this will affect the ParserCache capacity,
so we should monitor it after releasing this.

Change-Id: I154c0a77a5b0287b5572614d56339fb57ac56c33
2021-11-08 12:45:41 -08:00
Fomafix
0071df8981 EditPage: Only update title part of firstHeading on live preview
The message wgEditMessage can contain code for the extension
ParserFunctions which is not supported by mediawiki.jqueryMsg.

This change updates only the title in the firstHeading instead of
creating the whole message including the title again. The title gets
identified by a new HTML element with id="firstHeadingTitle".

The title in the HTML title gets not updated anymore. For a preview of
the display title the title in the firstHeading should be enough.

The 6 messages
'creating',
'editconflict',
'editing',
'editingcomment',
'editingsection',
'pagetitle'
are not needed anymore in JavaScript and removed from the module.

The global JavaScript variable 'wgEditMessage' is not needed anymore in
the live preview module. Other user scripts uses this variable and
therefor this variable is kept for compatibility.

Bug: T105214
Change-Id: I8d8dc79c6bf1a94a55f1d0f6b5611ca478fd9e18
2021-10-24 20:52:49 +00:00
Roman Stolar
fa5237eb48 Replace Content::getParserOutput call to ContentRenderer::getParserOutput
Bug: T287158
Change-Id: I8a13f45027e08e2d8ddefa140dd47a0c55094934
2021-10-20 12:11:24 +03:00
Umherirrender
f7fd5338dc Fix nullable doc for EditPage::$editRevId
Change-Id: Id79b5f3a34779f18e035632de690200713d77640
2021-10-16 22:31:28 +02:00
jenkins-bot
ae5c51f354 Merge "Use Message::sizeParams to simplify code when building messages" 2021-10-15 23:21:38 +00:00
DannyS712
751dccfb12 Minor cleanup to EditPage, should be a no-op
Make some things simpler

Change-Id: Id438f928eaa588640922ba74a907f5ff75f65522
2021-10-14 00:16:54 +02:00
Umherirrender
02c0e8b8e7 Use Message::sizeParams to simplify code when building messages
Change-Id: Ic04d4dea86e61fb07b2a3b17acb6021fab6ae5ee
2021-10-13 19:52:41 +00:00
jenkins-bot
10490802e7 Merge "Change null to [] for html attributes on call of Html functions" 2021-09-29 16:20:41 +00:00
Umherirrender
0e4bb6d611 Change 'fromdbmaster' to WikiPage::READ_LATEST
Constants are harder to misspell

Change-Id: Ie1afcc8580cccf815df1cc97f05a5be81676d9f7
2021-09-26 19:27:33 +00:00
Derick Alangi
2432cc2bb4 Use PageUpdater's fluent interface as in some parts of our codebase
Some methods in the PageUpdater's class implements the fluent interface
design pattern. Use the fluent interface where need be.

Change-Id: If76a4b8c5070c20ed40038a4ee78e2d677de5180
2021-09-23 00:31:33 +01:00
Umherirrender
362a48e316 Change null to [] for html attributes on call of Html functions
Change-Id: Ia84f5b1f210396cba5daa7b9e8bb8c4069e0171d
2021-09-22 22:47:28 +02: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
Ammarpad
1cf4eab3ab ApiParse: Support hidden skins
Since $wgSkipSkins is meant to only 'remove skin from preferences',
it should not affect parsing with them.

So these skins need to be allowed here.

To achive this, this patch adds getInstalledSkins() method to SkinFactory
to provide the complete. The method supersedes getSkinNames() which does
the same thing but with ambiguous name.

Description of getAllowedSkins() has been corrected as it was slightly incorrect.

Bug: T237856
Change-Id: I0889b823d27f1a2830cc0205f5a21ed4de744e08
2021-09-20 09:29:24 +01:00
Kunal Mehta
c27a559a93 EditPage: Read from wpWatchlistExpiry form value on "show changes" too
To allow people to set a custom watchlist expiry and then preview the
page, we read from the POSTed 'wpWatchlistExpiry' value and set that
as the default.

It seems reasonable and what users expect to do the same for "show changes",
so check for $this->diff as well.

Bug: T291287
Change-Id: Ia3b27b61a5c65b1830045796a87f11a5659502e2
2021-09-17 11:10:59 -07: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
jenkins-bot
79615a43c1 Merge "Drop wgAjaxEditStash, deprecated in 1.36" 2021-09-07 16:45:22 +00:00
jenkins-bot
8d2bdc20c2 Merge "Specify DB to query when checking if a user is blocked from a page" 2021-08-26 17:43:34 +00:00
Umherirrender
864068d000 Remove unneeded explicit true/false inside conditions
The non-strict conditions in if/while are true/false without the check.

In some situation the true/false is removed, because it is known to be a
bool (by is_bool check or type hint)

Change-Id: I5ca4c4771af25d2e785e82732df204a73653886e
2021-08-17 21:52:34 +02:00
jenkins-bot
0640586f88 Merge "Move Content::preloadTransform to ContentHandler" 2021-08-17 15:37:12 +00:00
Roman Stolar
42442e01ff Move Content::preloadTransform to ContentHandler
Update ContentTransformer to access ContentHandler::preLoadTransform through the service.
Prepare object to hold a data that required for ContentHandler::preLoadTranform params.

This is a fully backwards compatible change.
We are doing hard deprecation via MWDebug::detectDeprecatedOverride.

However, with the ContentHandler calling Content and
Content calling ContentHandler, it doesn't matter whether
callers use Content or ContentHandler. This will allow us
to naturally convert all callers.

Bug: T287157
Change-Id: I89537e1e7d24c6e15252b2b51890a0bd81ea3e6b
2021-08-17 15:17:34 +00:00
mainframe98
3bab2cc853 EditPage: load mediawiki.interface.helpers.styles
This module provides styling for span.comment, produced by
Linker::commentBlock, which EditPage calls when generating the
HTML for the edit summary.

Add a notice for that to Linker::commentBlock, like was done
in ddbf011257, and update the
comment in the stylesheet.

Bug: T288907
Change-Id: I3d929eaae54754bd3e41a9add419f1098a7f8e3a
2021-08-15 16:01:07 +02:00
jenkins-bot
9ca808f577 Merge "Support fluent interface for StatusValue" 2021-08-11 04:23:17 +00:00
Thiemo Kreuz
69242b0876 Various updates and fixes to PHPDoc documentation
Some minor updates I collected in my local dev environment the
past months.

Change-Id: I30d5339bc262d54ba76e2860a3a3e9e5f002fdc3
2021-08-09 09:26:23 +02:00
jenkins-bot
e89e7aa8b0 Merge "Revert "Use CsrfTokenSet as CSRF token source"" 2021-08-05 23:37:31 +00:00
Umherirrender
21e3caa033 Remove explicit LIMIT 1 when using IDatabase::selectRow/selectField
The limit is the reason why there is an explicit function to use

Change-Id: Ic85cb80b10f233fad4f8ffa214848d76092aee91
2021-08-06 00:54:47 +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
Umherirrender
d87dc4d99a Change Title::mNamespace to ::getNamespace() in EditPage
Change-Id: I852309cc88c2cddbd19c5c51c1f9c4be642c3ae3
2021-08-04 05:18:55 +02:00
James D. Forrester
1ca1b910c5 Drop wgAjaxEditStash, deprecated in 1.36
Bug: T274695
Change-Id: Ia51d889fff5132ff4f9a89d07bc04cc72f936f1f
2021-08-02 12:21:56 -07:00