Commit graph

243 commits

Author SHA1 Message Date
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
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07:00
Umherirrender
4f602d4d01 Use HTMLForm::setWrapperLegend and ::setSubmitTextMsg to set messages
setWrapperLegendMsg and setSubmitTextMsg are calling Message::text
Replacing setSubmitText + Message::text with setSubmitTextMsg makes the
code easier to read

Change-Id: I73389991fea82e1927027dc95c3debc3d8c15939
2021-06-15 18:56:49 +00:00
Petr Pchelko
15f2576886 Remove most usages of User from ProtectionForm
Change-Id: I7571f70c21f725474ab0e1b0f59e40acd9190077
2021-06-07 11:41:47 -07:00
Bartosz Dziewoński
65b23eb0fb ProtectionForm: Use XmlSelect::parseOptionsMessage where appropriate
Previously done in 02db290c64, looks
like it was accidentally undone in 1262ca1897.

Change-Id: I227ed9c6ba146fa249756f444f5c96ac2b5022b6
2021-05-25 18:44:51 +00:00
mainframe98
23cc232837 SECURITY: Fix XSS vulnerability in EditPage and ProtectionForm
The documentation of OutputPage::wrapWikiMsg says it is
equivalent to OutputPage::addWikitextAsInterface called
with wfMessage()->plain(). This is correct, as it parses
it in addWikitextAsInterface. If used with addHtml, no
parsing/escaping is done automatically.

Follow-up to I83f2828bcde160c98a1d97e783a869e64fb4c6ea.

(NOTE: the above, related change set is NOT currently
on a wmf production release branch.  So this issue only
exists on master for now.  This should all be resolved
when both are part of the cut for wmf.4 next week.)

Bug: T281595
Change-Id: Ia6c7a7447e5cea903be9f5d9e76320ea56fedd4c
2021-05-01 01:16:35 +00:00
mainframe98
c87462097c Don't use classes error, success and warning outside parser
Bug: T280766
Change-Id: I83f2828bcde160c98a1d97e783a869e64fb4c6ea
2021-04-27 17:11:14 +02: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
mainframe98
a6a051340c Create mediawiki.actions.styles module for misc action styles
These are styles for actions that do not have a dedicated style module.
Given that the amount of css it contains it marginal, creating a
dedicated module for each action would be overkill.

Bug: T278504
Change-Id: Id03c81e7d5ebf179731649aa230def2e8e21ac02
2021-03-31 15:39:51 +00:00
jdlrobson
20db32143b field descriptors in HTMLForm must have keys
Use the name of the input for the value where possible.

Additional change: Use `default` rather than `invert` for checkbox
default state.

Bug: T275018
Bug: T274980
Change-Id: Ie08b192ad4967ac6c6d80b9c76224acd183fc1e8
2021-02-19 01:17:02 +01:00
brandonxlf
1262ca1897 Use OOUI for protection form
Breaking changes:
  * Ids 'mwProtectSet', 'mw-protect-table3', and
    'mw-protect-table-$action' are no longer present on page.
  * Module 'mediawiki.legacy.protect' has been removed and replace by
    'mediawiki.action.protect'.

Deprecations:
  * ProtectionForm::buildForm has been replaced by
    ProtectionForm::addFormFields with backwards compatibility.

Other changes:
  * Expiry is no longer editable when "Allow all users" is selected
  * When "Unlock further protect options" is disabled, the expiry of
    the first section is used for the other sections
  * Legacy form elements added by extensions are added to a separate
    section which uses a blank i18n string as the header
  * Unprivileged users see the expiry selector instead of the expiry
    text input as it has the expiry date

Changes to ProtectionForm.php are based off of
I95d0289acceaa7ede789d5a6ea094fae757af6dc.

Bug: T235424
Bug: T236218
Change-Id: Ib22a3b53c1933e107ef5609bb2262aa44b5abb7a
2021-01-30 00:19:02 -05: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
0b6f5d9d78 ProtectionForm: Use available permission manager, not MediaWikiServices
Change-Id: Ia07a86f81af0ee777c66f3ded49010c9694795e9
2020-07-13 07:11:05 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Reedy
f43c2b76a3 Explicit visibility modifiers in ProtectionForm.php
Change-Id: Ie632feb583e500fb591d5deed48bbf83642ee6b9
2020-05-09 22:52:04 +00:00
jenkins-bot
e1d49a7113 Merge "Unify handling of options messages" 2020-04-06 23:20:44 +00:00
ArtBaltai
726a2650d3 Remove direct access to Action::page and Article::page properties
Bug: T239975
Change-Id: Id0d4d1e099edbdd67cabbed423dfff68cc48d323
2020-03-27 04:10:51 +00:00
Sam Wilson
02db290c64 Unify handling of options messages
There are a few messages that use a custom format for select
lists. This moves the parsing of these messages into a single
method.

Bug: T245565
Change-Id: I0a24d3458979d7cca2dc3cb38c1b0f700a88490a
2020-03-27 11:19:43 +08:00
DannyS712
7186b63f82 Hard deprecate Title::getUserPermissionsErrors
Remove final uses as well

Bug: T244929
Change-Id: I65e937c7b9904b1e93f649508b14148849589f82
2020-02-26 05:09:55 +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
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00
Umherirrender
db3a8beb77 Pass language to Status::getWikiText
Avoid use of $wgLang

Change-Id: I9cd633a20c5c60e56a101a9a699eea6db8b8eef0
2019-09-21 11:14:54 +00:00
Daimona Eaytoy
9699158f74 Declare dynamic properties
This is for all classes with 2 or more undeclared properties.

Change-Id: I1d80deb31f331bcc277b33f9e9f74857ba825637
2019-09-13 17:54:37 +00: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
Umherirrender
49c618d833 Fix param documentation of ProtectionForm::show
It also allows array

Change-Id: I513d6fd356933a2c2f45a1773dd2f59b967a1bf2
2019-06-29 17:22:44 +02:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Derick Alangi
c1e9a7c6df ProtectionForm: Follow up on I167ae6300b37d4e9292
Per code search string "\$this\-\>showLogExtract\( \$ou", method
is only called within the ProtectionForm class so can be safely
made private but there are methods with the same name in a class
like LogEventsList but do different things.

Inspired by @Thiemo's comment on I167ae6300b37d4e9292.

Change-Id: Ic4983ccffecc6285f848d6e926017c4c6df4855f
2019-03-16 21:12:18 +00:00
Derick Alangi
a6bd784b9b ProtectionForm: Add type hint to ::showLogExtract() header
https://codesearch.wmflabs.org/core/?q=showLogExtract%5C(&i=nope&files=&repos=
according to codesearch shows that this method takes as first argument an output
page object and also, objects are passed by reference by default so removed &.

Change-Id: I167ae6300b37d4e9292bd8ad14351f1ca35184d2
2019-03-10 19:12:48 +01:00
Fomafix
3ffc32ab8b ProtectionForm: Move JS config var to RL packageFiles
The check for type Array of the JavaScript config variable is obsolete.

Change-Id: I4a38cfc211360c831958ce8ca88584cdf56a727c
2019-02-11 12:20:01 +01:00
Kunal Mehta
cc5d9a92a2 build: Updating mediawiki/mediawiki-codesniffer to 24.0.0
Change-Id: I66b1775b7c1d36076d9ca78cbeb42787a743f2aa
2019-02-07 18:39:42 +00:00
Brad Jorsch
0abb9338f8 Mostly drop old comment schemas
This removes most of the pre-CommentStore text columns, and the
$wgCommentTableSchemaMigrationStage setting that used to determine
whether the columns were used.

rev_comment remains in the code, as on Wikimedia wikis the revision
table is too large to alter at this time. A future change will combine
that with the removal of rev_user_text, rev_content_model, and
rev_content_format (and the addition of rev_comment_id and rev_actor).

CommentStore's constructor continues to take a $stage parameter, and
continues to have the logic for handling it, for the benefit of
extensions that might need their own migration process.

Bug: T166733
Change-Id: I1479c73774e01ead1490adf6128f820c09bce9d4
2019-02-07 16:59:27 +11:00
C. Scott Ananian
97d9659904 Replace deprecated calls to OutputPage::parseInline()
Every one of these seemed to previously use the wrong value for
`$interface` -- the interface messages in ProtectionForm and
SpecialVersion were being parsed as content language (which is the
default for `OutputPage::parseInline`), and the one place where we
have actual data in the content language (the user signature, which
gets parsed in the content language with the rest of the (talk) page
content, see Parser.php::pstPass2) was being parsed as an interface
message!

Forcing the caller to be very explicit about AsContent() or AsInterface()
will help mitigate this in the future, one hopes.

Bug: T198214
Change-Id: Ib9d5d8d733a47c967bdf7db3e23fa39f11687063
2018-10-29 15:34:43 -04:00
C. Scott Ananian
c0ed262053 Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()
This change ensures that the output is tidy, and is necessary to support
future parsers which will not be able to produce untidy output.

Bug: T198214
Change-Id: I743f4185a03403f8d9b9db010ff1ee4e9342e062
2018-10-17 10:35:28 -04:00
C. Scott Ananian
e8a53ecf36 Use <div> wrappers instead of <p> in ProtectionForm
<p>-wrappers are fragile in case the wrapped content contains `<div>`,
`<p>` (or wikitext double newlines).  Use <div> wrappers consistently
in MediaWiki.

Bug: T205624
Change-Id: Ieee77f4220c7895ac5dccb2b638baef0dc22c84f
2018-09-27 11:44:15 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Bartosz Dziewoński
5c7b0addd5 Allow limiting comment length by characters rather than bytes in JS
For unfortunate historical reasons, browsers' native maxlength counts
the number of UTF-16 code units rather than Unicode codepoints [1],
which means that codepoints outside the Basic Multilingual Plane
(e.g. many emojis) count as 2 characters each. That could be good
enough, but we want our software to be excellent rather than merely
good enough.

1. Introduce a few new functions, added to the existing modules:
   * mediawiki.String:
     * codePointLength() counts the length of a string in Unicode
       codepoints (characters).
     * trimCodePointLength() trims a string to the desired length in
       Unicode codepoints (characters).
   * jquery.lengthLimit:
     * $.fn.codePointLimit() enforces the specified maximum length in
       codepoints of an input field.
   * mediawiki.widgets.visibleLengthLimit:
     * mw.widgets.visibleCodePointLimit() enforces the maximum length
       in codepoints of an OOUI widget and displays the remaining
       length in an inline label.

2. Add client-side mw.config variables:
   * wgCommentByteLimit for the old byte limit, equal to 255.
   * wgCommentCodePointLimit for the new codepoint limit, equal to 1000.

   Only one of them may be set, depending on which limit should be applied.

3. Make use of both of these new features. For the sake of an example,
   I updated the forms shown on action=edit (using visibleCodePointLimit)
   and on action=protect (using codePointLimit). Many remain to be updated.

[1] https://www.w3.org/TR/html5/sec-forms.html#limiting-user-input-length-the-maxlength-attribute

Bug: T185948
Change-Id: Ia1269fd898dabbcf1582618eab46cef97e10a3b1
2018-02-23 22:12:29 +00:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
jenkins-bot
258761ce1e Merge "Revert "Added reason suggestion in block/delete/protect forms"" 2017-01-21 19:47:27 +00:00
Florianschmidtwelzow
4b49705613 Revert "Added reason suggestion in block/delete/protect forms"
See the task, this was probably entirely my fault not having
looked at this more carefully. Technically the change is ok,
however, it seems to doesn't make much sense in combination
with the Reason dropdown box.

This reverts commit faab2411c2.

Task: T34950
Change-Id: I1eeb9c68ff0db20d29e7d5f0fb18f0bfa3224416
2017-01-21 20:03:45 +01:00
Yuriy Shnitkovskiy
55667f024d Replaced all deprecated Linker methods with proper ones in core(1)
Change-Id: Ie3a718dc1eae1507f8829fcf419c64c6846d2cb6
2017-01-20 11:46:13 +02:00
rlot
8c7095be85 Improved parsing in reason suggests
Bug: T155086
Change-Id: I3a3167b7bfd9b5921df1cf3e4a3cf3e1da4ca001
2017-01-11 19:00:00 +01:00
rlot
faab2411c2 Added reason suggestion in block/delete/protect forms
Bug: T34950
Change-Id: I9778c4992b127c36355949665b4fdf7482e7e0e7
2017-01-10 21:18:51 +00:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00
Aaron Schulz
56f8bde0fc Avoid master queries on GET in ProtectionForm
Bug: T92357
Change-Id: I58c5e793164faaafeea45ec5e986edcc7537ccab
2016-05-09 22:12:38 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Amir E. Aharoni
ddbba62d03 Make lines short to pass phpcs in 2 files under includes/
Bug: T102614
Change-Id: Iae4d4fbdba88ebcd9bcb018a2a0015d0c0ac607c
2015-09-30 05:20:03 +00:00
Geoffrey Mon
0d83dd176f Use XmlSelect in ProtectionForm
Bug: T93234
Change-Id: I47e08fb364dda6e4f59cd84c4c135e267e2c7bd9
2015-07-30 20:00:41 +00:00
umherirrender
f32e0cdd3a Use Linker::linkKnown for some links to MediaWiki pages from navigation
The title used for Linker::link in all places are mediawiki pages, which
are known to be exists (and blue), because there are definied in en.json

Change-Id: Ib3b6e4f4f6cef059a502aaabfcfc17730b4445a6
2015-06-19 18:55:30 +02:00