Commit graph

1650 commits

Author SHA1 Message Date
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
Bartosz Dziewoński
d0c84a8c68 EditPage: Add 'warningbox' to cascading protection note for consistency
Other protection warnings displayed by this function (via
LogEventsList::showLogExtract) are already styled that way
since 6fd6651c17.

Change-Id: Ibd1bb553ae012e55d8e3227ebc61b0d32c686e66
2020-01-30 11:26:49 -08:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Kunal Mehta
08b90824f4 EditPage: Include class name ::getContextTitle() deprecation warning
Some subclass is not calling ::setContextTitle(), but __METHOD__ is useless
here since it doesn't give us the name of the subclass, just 'EditPage'.

Use `get_class( $this )` instead.

Bug: T176526
Change-Id: I3652df98199c758e9ed8615263caf572e1d74695
2020-01-01 15:19:56 -08:00
Umherirrender
5478734bc7 Fix doc for EditPage::scrolltop
It is set from WebRequest::getIntOrNull

Change-Id: I9def9907a6666be7fc916afff9a8552806fce681
2019-12-28 23:44:40 +01:00
jenkins-bot
ad63f697e1 Merge "Set method visibility in some classes" 2019-12-09 16:34:27 +00:00
Umherirrender
4680496455 Set visibility on PermissionManager RIGOR_ constant
Use the constant instead of strings in some places

Change-Id: Ic14456ec9e863def05ec4dfbccb2fa8bd828e639
2019-12-06 22:18:01 +01:00
Umherirrender
925e3eb30b Set method visibility in some classes
Change-Id: I3c3d59d4b3edf2459efeac890721a43475e27198
2019-12-05 17:42:55 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Brad Jorsch
6070db3140 EditPage: Improve handling of missing revision contents
Historically, if the content of a revision was missing (e.g. a bad entry
in the `text` table), EditPage would display an empty textarea.
Ia94521b7 accidentally broke that, causing an uncaught exception.

This patch restores the previous behavior, with the addition of a notice
at the top of the page that the content couldn't be loaded.

This also cleans up the missing section handling so it isn't so easily
confused with other failures (and also so it doesn't pass false to a
method declared as taking Content|null).

Bug: T237570
Change-Id: Ia70de11c2e4833b202fde3028a1a94dfc741f0a5
2019-11-07 11:47:59 -05:00
WMDE-Fisch
5eef5a6654 Count edit conflicts combined with user edits
Bug: T236886
Change-Id: I275de8e806b9b29329c7757c4bb96ecd7ba0ea1f
2019-11-01 13:28:12 +01:00
jenkins-bot
090d20b682 Merge "Allow user, language and IP to be passed to UserBlockedError" 2019-10-18 22:29:13 +00:00
Max Semenik
bdf7e3f5bd Set constant visibility, part 1
Change-Id: I3dad26b1a0bd469fa84fee5c15d9b581765ceb94
2019-10-18 02:19:24 +00:00
Thalia
538d333167 Allow user, language and IP to be passed to UserBlockedError
Accept these objects as params to the UserBlockedError constructor,
since they are used to make the block error message. Pass them from
SpecialPages, Actions and EditPage.

If a caller does not pass all of these params, get them from the
global context as before.

Bug: T234406
Change-Id: Ie8ef047d2710c523b67bfc54fa2ad70fc47c5236
2019-10-17 15:19:28 +01:00
Timo Tijhof
0e1e4ee5de
block: Allow cookie-block tracking from any uncached web request
This was previously hardcoded from three places: 1) Upon viewing EditPage,
2) Upon viewing SpecialCreateAccount, 3) For any url if the user is
logged-in (User::loadFromSession/isLoggedIn).

== User::loadFromSession

Performing cookie blocks from here created a circular dependency because
Block may need the user language for localisation, which is determined by
asking the User object. This was previously worked around by using a
DeferredUpdate (T180050, T226777). Moving this logic explicitly to the
end of the pre-send cycle in MediaWiki::preOutputCommit breaks the cycle.
This is also where other request-specific handling resides already.

== Limited effect on unregistered users

When an unregistered user performs an edit, and gets blocked,
the cookie block is not applied until they open built-in editor
or CreateAccount page. This makes it more likely for a user's
IP to change meanwhile. Either intentionally, or simply due to
IPs varying naturally (e.g. between mobile locations, or when
going on/off WiFi). By applying it throughout sessioned page
views for unregistered users, it is more likely to get set.
Similar to what was already done for logged-in users.

This commit also makes the intent of not caching EditPage and
SpecialCreateAccount explicit. This was previously implicit
through nothing having called setCdnMaxage() and/or due to
Session::persist being checked for by OutputPage::sendCacheControl.

Bug: T233594
Change-Id: Icf5a00f9b41d31bb6d4742c049feca0039d0c9d9
2019-10-01 13:52:58 -04:00
Umherirrender
db3a8beb77 Pass language to Status::getWikiText
Avoid use of $wgLang

Change-Id: I9cd633a20c5c60e56a101a9a699eea6db8b8eef0
2019-09-21 11:14:54 +00:00
Umherirrender
268346e562 phan: Enable PhanTypeMismatchArgument issue
Bug: T231636
Depends-On: I5de4f8f32a47c3f41c990ffe2ebd091fc23d1a58
Change-Id: I34d65fe3ff1916f2af675f0b1f19641b0cdfadc0
2019-09-19 20:11:42 +02:00
Daimona Eaytoy
e5444ea55a docs: Avoid some scalar juggling
Phan can treat scalar types as non-interchangeable with
`scalar_implicit_cast` set to false. This patch fixes some of those
issues (which are in total >1000), namely the ones with alphabetic order
< includes/actions.

Change-Id: Ib1c6573ab899088bc319b9da9ceaffc850da3dbe
2019-09-19 17:21:24 +00:00
jenkins-bot
2aed14b686 Merge "Standardise preview warning box when using ?action=edit" 2019-09-17 02:06:54 +00:00
jenkins-bot
74da7f603f Merge "Update docblocks for methods potentially returning null" 2019-09-15 16:27:34 +00:00
Daimona Eaytoy
dddc912fd6 Update docblocks for methods potentially returning null
These were discovered by setting `null_casts_as_any_type` to true in
phan, and filtering by `PhanTypeMismatchReturnNullable`. Of course there
are others, some of which are false positives, but we cannot suppress
them now (or the UnusedSuppressionPlugin will complain).

Change-Id: Ia8443e575c22f47a6d8c63038f4e7ac36815fc27
2019-09-15 15:22:39 +00:00
Umherirrender
f74400487f phan: Disable enable_class_alias_support
It is enabled for b/c in extensions, but not needed in core

Change-Id: I51dca12be9c77049f77563d9bf0edd07928c2300
2019-09-15 08:26:52 +00:00
jdlrobson
c2b9f7d074 Standardise preview warning box when using ?action=edit
If editing without JS, and clicking preview on action=edit
you will see a preview with a note at the top of the page.
McrUndoAction.php uses a close copy of the same code and will
be amended accordingly.

Currently this is using a class `.previewnote` and not the
standardised and semantic "warningbox".

The messages of the preview will now be warningbox's
- see screenshots for end result:

* https://phabricator.wikimedia.org/F30284946
* https://phabricator.wikimedia.org/F30284947

Bug: T232414
Change-Id: Ib678f03e908fa9dcd5af7632941475203478abf7
2019-09-10 17:01:04 -07:00
jenkins-bot
4051e45504 Merge "Make wgDisableAnonTalk disable anon links in automatic edit summaries" 2019-09-08 02:54:56 +00:00
DannyS712
bbeeddeafb Make wgDisableAnonTalk disable anon links in automatic edit summaries
Bug: T31539
Change-Id: Ie866e66b95cb36058a78ad86af8f5fe63f63ab1c
2019-09-06 23:04:39 +00:00
jenkins-bot
a389d94551 Merge "EditPage: Don't set 'hookaborted' error if the hook set a better error" 2019-09-04 15:27:44 +00:00
Daimona Eaytoy
e2e543f7c2 Unsuppress more phan issues (part 5)
Bug: T231636
Depends-On: I6e5fba7bd273219b1206559420b5bdb78734aa84
Change-Id: I50377746f01749b058c39fd8229f9d566224cc43
2019-09-01 09:48:31 +00:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
daniel
6906a7728c Add UnknownContentHandler.
UnknownContentHandler can be configued to handle models that
belong to extensions that have been undeployed:

  $wgContentHandlers['xyzzy'] = 'UnknownContentHandler';

This way, no errors will be thrown when trying to access
pages with the unsupported model. Instead, an error message is
shown, and editing is prevented.

This patch also improves handling of non-editable content in
EditPage and in DifferenceEngine.

Bug: T220608
Change-Id: Ia94521b786c0a5225a674e4dc3cb6761a723d75b
2019-08-29 10:43:11 +00:00
Bartosz Dziewoński
e03ae008f0 EditPage: Don't set 'hookaborted' error if the hook set a better error
When the 'EditFilterMergedContent' hook set an erroneous status but
did not abort execution (hook function does not return false), we
always added a 'hookaborted' error to the status, regardless of what
was already set.

This mistake was not visible in the edit form, because error message
formatting was incorrectly done before that (which would actually emit
a different error if none was set).

However, the additional error code propagated to the API, where it was
emitted when using 'errorformat=html' (or any other format except the
default 'bc', which can only produce one error code/message).

This affects various extensions, including EventLogging, UploadWizard,
AbuseFilter (after I5424de38) and SpamBlacklist (after Id36aa6bd).

----

You can test this behavior with these two simple hooks:

// A: Set error status and error message
$wgHooks['EditFilterMergedContent'][] = function ( $context, $content, $status ) {
  $status->fatal( 'test-message' );
};

// B: Set error status but no error message
$wgHooks['EditFilterMergedContent'][] = function ( $context, $content, $status ) {
  $status->setOK( false );
};

Adding either of them to your LocalSettings will cause all edits to
fail as follows:

Before this patch:
         | Error message in the UI   | Error code in the API     |
| Hook A | test-message              | test-message, hookaborted |
| Hook B | internalerror_info        | hookaborted               |

After this patch:
         | Error message in the UI   | Error code in the API     |
| Hook A | test-message              | test-message              |
| Hook B | hookaborted               | hookaborted               |

Bug: T231253
Change-Id: I106dbd3cbdbf7082b1d1f1c1106ece6b19c22a86
2019-08-26 23:25:09 +02:00
Petr Pchelko
3cc3d00bcc Move getRestrictionLevels from NamespaceInfo to PermissionManager.
Bug: T11977
Change-Id: I051be9148c98086fdf53a66a74bf7c28699016db
2019-08-22 14:32:38 -07:00
Petr Pchelko
1d286560d2 Replace User::isAllowed with PermissionManager.
Covers root includes, actions, api, block, changes,
changetags, diff and PermissionManager itself.

Bug: T220191
Change-Id: Ic027d32f5dd8f4c74865df0c8a9fcf91123c889c
2019-08-20 14:43:51 -07:00
Thalia
5f89f7040f Fix grammatical error in several comments
Change-Id: Ibd8ad594950d53f5feb337c30f184ecaf218bc81
2019-08-08 14:02:13 +01:00
Derick Alangi
434d740d90 Avoid usage of deprecated Revision::* constants
Change-Id: I2d06bbacef88573f286da25994a3ad434ed90e9c
2019-07-21 18:02:58 +01:00
Derick Alangi
339211a1ea Avoid usage of deprecated Revision::* constants, use RevisionRecord
Change-Id: I872fc89e5c02dd6a3ae9cd7e76640b95dc33f514
2019-07-21 15:03:03 +01:00
Derick Alangi
2dca5bbbf5 Remove unnecessary semi-colons
Change-Id: I9eb65bdfbd3aa581effc14ead801b9e89b0359c3
2019-06-12 14:35:59 +01:00
jenkins-bot
cb349fb447 Merge "Move cookie-blocking methods to BlockManager" 2019-06-11 15:16:00 +00:00
Thalia
c5991f614f Move cookie-blocking methods to BlockManager
Move the cookie blocking logic into one place. Specifically, move
these methods to the BlockManager:
* User::trackBlockWithCookie
* DatabaseBlock::setCookie
* DatabaseBlock::clearCookie
* DatabaseBlock::getCookieValue
* DatabaseBlock::getIdFromCookieValue
* AbstractBlock::shouldTrackWithCookie

After this, BlockManager::trackBlockWithCookie should be called to
track a block, and BlockManager::clearBlockCookie should be called
to unset the cookie. The other methods in the above list are
helper methods that are made private or marked internal.

Also update places in core that call User::trackBlockWithCookie to
BlockManager::trackBlockWithCookie

Bug: T225141
Change-Id: I818962c6932c01c841a549a101637e00a7593e48
2019-06-11 15:08:21 +01:00
Derick Alangi
21e2d71560 Replace some uses of deprecated wfFindFile() and wfLocalFile()
These global functions were deprecated in 1.34 and services made
available to replace them. See services below;

* wfFindFile() - MediaWikiServices::getInstance()->getRepoGroup()->findFile()
* wfLocalFind() - MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile()

NOTES:

* wfFindFile() and wfLocalFind() usages in tests have been ignored
  in this change per @Timo's comments about state of objects.

* includes/upload/UploadBase.php also maintained for now as it causes
  some failures I don't fully understand, will investigate and handle
  it in a follow up patch.

* Also, includes/MovePage.php

Change-Id: I9437494de003f40fbe591321da7b42d16bb732d6
2019-06-11 13:26:37 +00:00
jenkins-bot
f01c8c59fd Merge "Rename Block to MediaWiki\Block\DatabaseBlock" 2019-05-28 22:43:51 +00:00
Derick Alangi
078ac4b10b EditPage: Remove unused deprecated method ::submit()
Was deprecated in 1.29 and EditPage::edit() was made available for
use and replacement of this ::submit().

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5C-%5C%3Esubmit%5C(%5C)&i=nope&files=&repos=

The usage of ->submit() in the search link above are not for EditPage
but for other classes.

Change-Id: Ibd65965c785f84e9bda65cfaa2c491310cda8166
2019-05-28 19:29:51 +01:00
Thalia
e65a5b5882 Rename Block to MediaWiki\Block\DatabaseBlock
Keep Block as a deprecated class alias for DatabaseBlock.
Update calls to the Block constructor and Block static
methods from external classes.

Also update documentation in several places that refer to
blocks as Blocks.

Bug: T222737
Change-Id: I6d96b63ca0a84bee19486471e0a16a53a79d768a
2019-05-28 12:20:48 +01:00
Máté Szabó
b537e44c4e EditPage: Migrate Title::userCan() calls to PermissionManager
T208768 introduced the PermissionManager service that can now be used
for page specific permission checks. This change replaces calls to
Title::userCan() with the new service in the EditPage class.

Bug: T220191
Change-Id: I835d68d6c47785cf35386bca0431907fee87f0c1
2019-05-18 20:49:21 +02:00
jenkins-bot
81c91fd493 Merge "Remove unused title parameter from EditPage::getEditToolbar()" 2019-05-10 16:20:09 +00:00
Thiemo Kreuz
b4115ca9cf Remove unused title parameter from EditPage::getEditToolbar()
No code uses this parameter:
https://codesearch.wmflabs.org/search/?q=getEditToolbar
I suggest to skip any deprecation because of this.

It might be worth mentioning this in the release notes anyway, or is
it?

Change-Id: I5d47c22fa741df5f9c248e4e1bff2d6e97aca6a7
2019-05-10 15:23:20 +02:00
Derick Alangi
d2a7f802cf EditPage: Remove ::safeUnicodeInput() and ::safeUnicodeOutput()
These methods were deprecated in 1.30 are now being removed as there
are no longer any usage of them.

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5Cb(safeUnicodeOutput%7CsafeUnicodeInput)%5Cb&i=nope&files=&repos=

Bug: T220656
Change-Id: Idd36a81593b9e4e48a43c497c620c3f7d0b0554b
2019-05-09 19:47:49 +01:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Dayllan Maza
dadaf0ac2c Remove block notice tracking
This is a clean up after collecting the necessary data related to
blocks and how often users see the block notices

See: https://phabricator.wikimedia.org/T189724

Bug: T214214
Depends-On: I047587c064e63e8bd4b933351edfec298f7c7956
Depends-On: I532a0cd95009109ba25caa8dd31badd5c1900da7
Change-Id: Icfa74ad6337c0a4f12ae24b43d36c0e3cb302a3b
2019-04-23 17:49:12 -04:00
Aryeh Gregor
e6df285854 Remove all $wgParser use from core
Bug: T160811

Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
2019-04-17 15:16:50 +03:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00