Commit graph

136 commits

Author SHA1 Message Date
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
jenkins-bot
998af2a6b9 Merge "Use Authority and GroupPermissionLookup in Action API" 2021-02-23 16:03:56 +00:00
Cindy Cicalese
f6e1891c6f Use Authority and GroupPermissionLookup in Action API
Replaces calls directly to PermissionManager with calls to
the Authority object available from Context or the
GroupPermissionLookup service.

This patch does not address use of PermissionManager for
blocks.

Deprecations:
- ApiBase::checkUserRightsAny deprecated passing optional
User parameter
- ApiBase::checkTitleUserPermissions deprecated passing
LinkTarget as first parameter, takes PageIdentity instead

Bug: T271462
Bug: T271854
Change-Id: I5d7cac1c28a37e074750c46cda03283980a07fca
2021-02-23 14:31:14 +00:00
Thalia
0be0162841 ApiQueryUserInfo: Allow all uiprops to be requested at once
This is useful for use cases such as T272412, which allows any user
to see all their info via their preferences.

Bug: T275441
Change-Id: I99e576bd9ad3980ee0fa8397409ef0c7e248a175
2021-02-22 21:46:42 +00:00
Cindy Cicalese
f8e1fcacbb Use UserEditTracker in ApiQueryUserInfo::getLatestContributionTime()
Bug: T273788
Change-Id: I5d53fbe84dc3904f042a0f183d8d92b4f9695036
2021-02-07 15:52:58 -05:00
Cindy Cicalese
5576727771 Make UserIdentity objects aware of which wiki they belong to.
Bug: T260933
Change-Id: Ic986640cc34e6ec6be239e410a8334f0e299c682
2021-02-02 16:10:51 +00:00
Reedy
56ba0a755a Revert "Remove usages and hard deprecate User::changeable(By)Group"
This reverts commit d70559796a.

Reason for revert: T273317 T273296

Bug: T273317
Bug: T273296
Change-Id: I0709ad630f4443d4cd2e5ea51105e1c9f409c12e
2021-01-29 20:32:57 +00:00
Petr Pchelko
d70559796a Remove usages and hard deprecate User::changeable(By)Group
Bug: T254838
Change-Id: Ie7fd852c287e91f16122ecb2d1bef5353fd40ea9
2021-01-21 20:53:40 +00:00
DannyS712
bc32baf912 ApiQueryUserInfo: Add theoreticalratelimits
Bug: T258888
Change-Id: If2848a4905ff165f1b1ba6f26aaad8697a3f7ea4
2020-09-15 18:56:56 +00:00
jenkins-bot
fedbf6ba82 Merge "Use new TalkPageNotificationManager" 2020-05-20 19:21:52 +00:00
Reedy
b80a9f4f6a Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I5e04824d6fa6a4c36ce489850bb0ed7b4ac588f9
2020-05-16 00:51:14 +01:00
Clara Andrew-Wani
b3a5c7c0d5 Use new TalkPageNotificationManager
Bug: T239640
Change-Id: I7c06d145854ab39faaef528e169f6b51de1c8d99
2020-05-15 12:35:45 -04:00
Thiemo Kreuz
c05bdcee8b Remove unreachable null checks after isset()
isset() does two things: It checks if a variable (or array element)
is declared, *and* it checks if it is null. If a variable is null,
isset() fails as if the variable was not set. All these additional
null checks are dead code.

Change-Id: I71e8cc26dac839c9d081bf00b4164b7b5147e586
2020-02-28 21:40:48 +00:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Thalia
7bbda9811b Remove deprecated method ApiQueryUserInfo::getBlockInfo
Change-Id: Ib291a7893cde780c3505f7cd499e222410e0efa9
2019-10-16 20:46:02 +01:00
Brad Jorsch
c29909e59f Mostly drop old pre-actor user schemas
This removes most of the pre-actor user and user_text columns, and the
$wgActorTableSchemaMigrationStage setting that used to determine
whether the columns were used.

rev_user and rev_user_text remain 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_comment, rev_content_model, and
rev_content_format (and the addition of rev_comment_id and rev_actor).

ActorMigration'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. Code using
ActorMigration for accessing the core fields should be updated to use
the new actor fields directly. That will be done for in a followup.

Bug: T188327
Change-Id: Id35544b879af1cd708f3efd303fce8d9a1b9eb02
2019-09-09 11:38:36 -04:00
Daimona Eaytoy
327e8ea416 Unsuppress phan issues part 6
Bug: T231636
Depends-On: I50377746f01749b058c39fd8229f9d566224cc43
Change-Id: I2cd24e73726394e3200a570c45d5e86b6849bfa9
2019-09-01 09:48:45 +00:00
jenkins-bot
80d2ef4683 Merge "Remove usages of deprecated User::getRights." 2019-08-21 08:15:34 +00:00
Petr Pchelko
5bebae7f96 Remove usages of deprecated User::getRights.
Bug: T220191
Change-Id: Ia7472cf61765fe5fee9ae72cfa9b7060565dbe87
2019-08-20 19:43:54 -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
f5ef28cadc Make ApiQueryUserInfo::getBlockInfo accept an AbstractBlock
This method was removed (I84ed216) before the Block class was
refactored (I83bceb5) and restored (If47a938) after the refactor.

After the refactor, this method should accept and AbstractBlock,
so it can handle a SystemBlock as well as a database Block.

Change-Id: Ice8a2e7c19e88406229bd836a45f377abdb72fb6
2019-05-13 15:20:38 +01:00
daniel
9f973228d5 Restore ApiQueryUserInfo::getBlockInfo() as a stub.
Fixes unintended breaking change made by I84ed21641c44b2f65ebe.
ApiQueryUserInfo::getBlockInfo() is restoed as a hard deprecated stub.

This renames the method in the new ApiBlockInfoTrait to
getBlockDetails.

Depends-On: I9f40666a31bd4af50762c197c2ce5bf089a5e68c
Change-Id: If47a93878f87d69800e5f305404c22528dac5e94
2019-05-11 07:33:25 +00:00
Amir Sarabadani
693c8b2f5a Move ApiQueryUserInfo::getBlockInfo() to ApiBase
ApiBase directly uses this method causing a cyclic dependency between
ApiBase and ApiQueryUserInfo

Change-Id: I84ed21641c44b2f65ebe1980b0893d1846db3b34
2019-05-06 00:06:30 +02:00
David Barratt
e86a060284
Deprecate User::isBlocked()
The method User::isBlocked() attempts to answer two questions:
(1) Does the user have a block?
(2) Is the user prevented from performing this action?
The method can answer #1, but it cannot answer #2. Since User::getBlock() can
also answer #1, this method is redundant. The method cannot answer #2 because
there is not enough context in order to answer that question.

If access is being checked against a Title object, all access checks can be
performed with PermissionManager:userCan() which will also check the user's
blocks.

If performing all access checks is not desirable, using
PermissionManager::isBlockedFrom() is also acceptable for only checking if the
user is blocked. This method does *not* determine if the action is allowed,
only that the user's block applies to that Title.

If access is being checked without an existing Title, User::getBlock() can be
used to get the user's block. Then Block::appliesToRight() can be used to
determine if the block applies explicitly to a right (or returns null if
it is unknown or false if explicitly allowed). If the user is creating a new
Title, but the text of the title is not yet known (as in the case of Wikibase),
access should be checked with Block::appliesToNamespace().

Bug: T209004
Change-Id: Ic0ad1b92e957797fee8dcd00bd1092fe69fa58f1
2019-04-25 11:47:44 -04:00
jenkins-bot
09ee5d2505 Merge "Add meta=userinfo&uiprop=latestcontrib" 2019-04-04 23:23:54 +00:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Max Semenik
c7408f2253 Add meta=userinfo&uiprop=latestcontrib
Returns the timestamp of user's latest contribution.

Bug: T208636
Change-Id: I73b20c61b9a46d308b406315fac05e5972d3009e
2019-03-22 17:54:02 -07:00
Thalia
1b9ca741a7 Remove reliance on Block properties being public
Use getters and setters for $mReason, $mTimestamp, $mExpiry and
$mHideName; use Block::getType to check if a block is an autoblock
instead of checking $mAuto; no change needed for $mParentBlockId,
which is not accessed externally.

Change-Id: I767ed44ce4c2e21f53962d75fb86891add2282f6
2019-03-22 21:17:22 +00:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
David Barratt
b3014df3b6 List Partial Block details in ApiQueryBlocks and ApiQueryUserinfo.
The ApiQueryBlocks and ApiQueryUserinfo endpoints will now return whether or not the block is
sitewide or partial. Partial block restrictions can be returned with ApiQueryBlocks.

Bug: T197141
Change-Id: I76eb4cac4dc989c621a00a39996faebd0eb9892c
2018-10-24 16:26:32 +00:00
Umherirrender
c9d303d39e Remove "Created on" from file header comments
It is the job of git and svn to provide this information/metadata.
The form was different, some with short, some with long month name
some with leading zero at the day, some without.
The year is also present in the Copyright clause

Change-Id: If006907b82b9e45f13cfa2e45d41107a95570e1a
2018-01-26 23:12:40 +00:00
Brad Jorsch
e2c949677e API: Add the ability to flag parameter values as deprecated
This has a number of implications:
* A deprecation warning is automatically generated if the value is used.
* action=paraminfo can list it in a machine-readable manner.
* It is automatically flagged in the help when message-per-value mode is
  used.
* In values lists in the help, it's specially marked (currently
  strike-through).
* ApiSandbox will mark it in the widgets (currently strike-through).

Deprecation of submodules is not automatically detected here, that's
left for a later patch.

Bug: T123931
Change-Id: Idad6377063e457f9352a99df5c7cc15b1563579e
2017-06-20 11:41:26 -04:00
Baha
036b9c4167 Make API documentation links language aware
Links generated by the API are now aware of the user's preferred
language and will show documents in that language if available.

To test, log in to mediawiki.org and set your language preference to 'es',
then on an MediaWiki installation with this patch view the generated
expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`.
Each link to documentation on mediawiki.org should take you to its
translated /es subpage, if one exists.

Bug: T104518
Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
2017-04-05 11:08:25 -04:00
This, that and the other
73224f4f8b User group memberships that expire
This patch adds an ug_expiry column to the user_groups table, a timestamp
giving a date when the user group expires. A new UserGroupMembership class,
based on the Block class, manages entries in this table.

When the expiry date passes, the row in user_groups is ignored, and will
eventually be purged from the DB when UserGroupMembership::insert is next
called. Old, expired user group memberships are not kept; instead, the log
entries are available to find the history of these memberships, similar
to the way it has always worked for blocks and protections.

Anyone getting user group info through the User object will get correct
information. However, code that reads the user_groups table directly will
now need to skip over rows with ug_expiry < wfTimestampNow(). See
UsersPager for an example of how to do this.

NULL is used to represent infinite (no) expiry, rather than a string
'infinity' or similar (except in the API). This allows existing user group
assignments and log entries, which are all infinite in duration, to be
treated the same as new, infinite-length memberships, without special
casing everything.

The whole thing is behind the temporary feature flag
$wgDisableUserGroupExpiry, in accordance with the WMF schema change policy.

The opportunity has been taken to refactor some static user-group-related
functions out of User into UserGroupMembership, and also to add a primary
key (ug_user, ug_group) to the user_groups table.

There are a few breaking changes:
- UserRightsProxy-like objects are now required to have a
  getGroupMemberships() function.
- $user->mGroups (on a User object) is no longer present.
- Some protected functions in UsersPager are altered or removed.
- The UsersPagerDoBatchLookups hook (unused in any Wikimedia Git-hosted
  extension) has a change of parameter.

Bug: T12493
Depends-On: Ia9616e1e35184fed9058d2d39afbe1038f56d7fa
Depends-On: I86eb1d5619347ce54a5f33a591417742ebe5d6f8
Change-Id: I93c955dc7a970f78e32aa503c01c67da30971d1a
2017-01-27 09:24:20 +00:00
Brad Jorsch
a066419628 ApiResult: Add ApiResult::formatExpiry()
This allows for removing $wgContLang from many API modules where it was
only used to call $wgContLang->formatExpiry() in a way in which the
results don't actually depend on the language.

Change-Id: Ib0f25f288b9b87d2e4131297c552e5971696db87
2017-01-11 11:11:19 -08:00
Brad Jorsch
01a3b2b0bf Add the concept of "system blocks"
Blocks made for configured proxies, dnsbls, or the configured range
soft-blocks being added in I6c11a6b9 aren't real blocks stored in the
database. Let's actually flag these blocks as such and use a more
appropriate message when displaying them to the user.

Change-Id: I697e3eec2520792e98c193200c2b1c28c35bf382
2016-12-16 12:30:03 -05:00
Brad Jorsch
4e6810e4a2 API: i18n for warnings and errors
API warnings and error messages are currently hard-coded English
strings. This patch changes that.

With a few exceptions, this patch should be compatible with non-updated
extensions:
* The change to ApiBase::$messageMap will blow up anything trying to
  mess with it.
* The changes to the 'ApiCheckCanExecute' hook will cause a wrong
  (probably unparsed) error message to be emitted for extensions not
  already using an ApiMessage. Unless they're currently broken like
  Wikibase.

Bug: T37074
Bug: T47843
Depends-On: Ia2b66b57cd4eaddc30b3ffdd7b97d6ca3e02d898
Depends-On: I2e1bb975bb0045476c03ebe6cdec00259bae22ec
Depends-On: I53987bf87c48f6c00deec17a8e957d24fcc3eaa6
Depends-On: Ibf93a459eb62d30f7c70d20e91ec9faeb80d10ed
Depends-On: I3cf889811f44a15935e454dd42f081164d4a098c
Depends-On: Ieae527de86735ddcba34724730e8730fb277b99b
Depends-On: I535344c29d51521147c2a26c341dae38cec3e931
Change-Id: Iae0e2ce3bd42dd4776a9779664086119ac188412
2016-12-06 10:20:48 -05:00
addshore
818984e5cb Remove WatchedItemStore::getDefaultInstance
Change-Id: I0c7d706fabee8d1f6fcfbc4c568f375953de8058
2016-05-06 08:47:37 +00:00
addshore
846d373c28 Add countUnreadNotifications to WatchedItemStore
This query / logic has been extracted from
ApiQueryUserInfo.

Unit & Integration tests have also been added.

Relating to the task linked this is the last change
needed in this ApiQueryUserInfo!

Bug: T129482
Change-Id: I91aa109416c16cd1f257c9de46669e35d6fd34d7
2016-03-14 16:00:47 +00: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
Brad Jorsch
72152a7ffc API: Allow querying central user info
meta=siteinfo gets a list of all configured central ID lookup providers
and which one is being used as the default, while meta=userinfo,
list=users, and list=allusers get the ability to return the IDs and
attachment status.

Change-Id: Iea15b6c22baac79b3f8ca6df0e20a6a4299507d2
2015-12-02 22:32:34 +00:00
Thiemo Mättig
3ecd418501 ApiBase::PARAM_DFLT => null is the default anyway
Change-Id: Ic3deeb6b3d7cacbdb85da9ba3cb19051c1182b8f
2015-10-05 10:56:32 +02:00
Siebrand Mazeland
0fdb0ce284 Fix most PHP CodeSniffer warnings in includes/api
Change-Id: I01bb3e4c96d6034a5b6c18728bb0574c710ea9db
2015-09-28 14:24:52 +02:00
jeroendedauw
3095012f12 Remove dead local var in ApiQueryUserInfo
Change-Id: I8620848f22bddd133b618a7c4918adbf7adcb8c0
2015-09-07 21:48:54 +02:00
umherirrender
c1f90160be API: Use message-per-value for apihelp-query+userinfo-param-prop
Use message-per-value for message
apihelp-query+userinfo-param-prop to allow smaller strings
for translation.
Each prop in a message also will show up a new parameter on the help
page without the adjust of the translation (but than in english instead
of fully skip it).

Change-Id: I7bb36e4fd95e68fe4798e31070b6fa05ac550d38
2015-08-06 10:17:34 +02:00
Alex Monk
78da7f1637 API: Give block details along with errors
Bug: T95072
Change-Id: I295d74d5f33e6dd1072a1e85710a02597a46e14d
2015-06-17 20:40:14 +01:00
RobinHood70
15ecc5a93a Update getHelpUrls() for reworked mw.org API pages
Community members restructured the mediawiki.org API pages, e.g.
the meta allmessages query submodule is no longer in the catch-all
https://www.mediawiki.org/wiki/API:Meta?oldid=1408361#allmessages_.2F_am
but its own https://www.mediawiki.org/wiki/API:Allmessages

The links in the generated API help, e.g.
https://www.mediawiki.org/wiki/Special:ApiHelp/query+allmessages,  are no
correct. They're not 404s but they don't take you directly to the
relevant page.

This patch set fixes the getHelpUrls() URLs (and does nothing else).
I tested them all.

Thanks RobinHood70!

Change-Id: Icea94abdd22d1ad468172642a21641e7c5ce2046
2015-05-04 08:15:54 +00:00
Brad Jorsch
beab6b009e Change API result data structure to be cleaner in new formats
Nothing in this patch should result in changed output for format=json or
format=php except as noted in RELEASE-NOTES-1.25, and changed output for
format=xml should be similar or cosmetic. However, other code accessing
the result data directly may need to be updated.

Bug: T87053
Bug: T12887
Change-Id: I3500708965cb8869b5aed1543381aad208dadd13
2015-04-20 17:49:37 -04:00
jenkins-bot
4fa0240228 Merge "API: Overhaul ApiResult, make format=xml not throw, and add json formatversion" 2015-04-16 01:05:51 +00:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00