Commit graph

608 commits

Author SHA1 Message Date
daniel
948123e589 Mark API base classes as extensible
This marks API base classes as stable for extending per the
Stable Interface Policy.

Bug: T247862
Change-Id: I164192ba3d013d8bc98a8b9c6db10e3dd1e58b23
2020-07-08 14:14:54 +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
Timo Tijhof
5d8f62bdd3 ExtensionRegistry: Remove exporting and caching of wgExtensionCredits
This data is the same as the 'credits' data that is already compiled,
cached and made available via ExtensionRegistry.

Similar to various other configuration variables previously, the
$wgExtensionCredits variable is now also required to only be used
for providing input to the system (e.g. from LocalSettings.php,
or from legacy extension PHP entry points). It is no longer
supported to use this variable to reliably read out a full view
of all extension credits (specifically those registered via
extension.json).

Doing so had the downside of adding processing cost to every
web request, as well as taking one the single largest portion
of the ExtensionRegistry APCu cache key, which in PHP7+ incurs
a linear cost for every string value, string key, of every
(sub)array in this huge structure; and does to on every request
just in case something reads from $wgExtensionCredits.

The new method to access this information reliably is owned
by SpecialVersion for now (could be moved elsewhere). This
also makes the merging logic more testable and incurs it on-demand
rather than upfront.

Details:

* Move 'type' internally from NOT_ATTRIBS to CREDIT_ATTRIBS.
  These two arrays behave identically for most purposes (they are
  both used to mean "don't export this as a global attribute").

  By placing it in CREDIT_ATTRIBS it becomes complete and makes
  it easy to refer to in docs. Previously, extractCredits()
  read the 'type' key outside the loop for CREDIT_ATTRIBS.

* Remove redundant code in ApiBase.php, that is now more obviously
  redundant. Looks like a left-over or merge conflict mistake
  from when ExtensionRegistry was first introduced.

Bug: T187154
Change-Id: I6d66c58fbe57c530f9a43cae504b0d6aa4ffcd0d
2020-05-28 18:46:41 +00:00
DannyS712
7ae0b3dc56 ApiBase::checkUserRightsAny - remove an extra tab
Change-Id: Id81e257c24f8eadb1fedcc47c71adfbfb939273a
2020-03-26 04:13:35 +00:00
Sam Wilson
bada529138 Reduce the length of 6 long lines of code
This shortens some lines below 120 characters when a tab is
counted as 4 characters (not that line lengths are currently
counted like that).

Bug: T243598
Change-Id: I828cd540268810bd56589885e38ad03f8bafc6f9
2020-03-13 09:01:14 +08:00
Reedy
511f9b5d95 Don't pass 'ip' through to logging
Bug: T245280
Change-Id: Ib89be9f799e79f46dab661a387822cab43703f61
2020-02-14 17:46:10 +00:00
Ricordisamoa
1b3bc281ac Clean up redundant Exception|Throwable union type
PHP 7.0 makes many error conditions throw instances of the new Error class
which does not extend the known Exception.
The Throwable interface provides a concise and type-safe way of handling
either, e.g. for logging purposes, but HHVM did not support it, requiring
tedious fallback checks.

This commit replaces occurrences of Exception in code paths equally
covered by Throwable, like Exception|Throwable parameter and return types
(also nullable), instanceof guards, duplicated `catch` blocks, as well as
related comments and documentation blocks, with the exception of $previous
parameter descriptions consistent with the manual at
https://www.php.net/manual/en/exception.construct.php

Proper type declarations have been added or reinstated where possible.

Change-Id: I5d3920d3cc66936a350314e2f19c4f6faeffd7c0
2020-02-12 20:28:40 +00:00
Brad Jorsch
c2b1525908 API: Use ParamValidator library
This brings significant modularization to the Action API's parameter
validation, and allows the Action API and MW REST API to share
validation code.

Note there are several changes in this patch that may affect other code;
see the entries in RELEASE-NOTES-1.35 for details.

Bug: T142080
Bug: T232672
Bug: T21195
Bug: T34675
Bug: T154774
Change-Id: I1462edc1701278760fa695308007006868b249fc
Depends-On: I10011be060fe6d27c7527312ad41218786b3f40d
2020-02-04 13:36:14 -05:00
DannyS712
df46acc56d Drop support for passing a User to ApiBase::checkTitleUserPermissions
Deprecated and unused

Bug: T241354
Change-Id: I7726eba3e583548a284bffb8a28df0767bda31b4
2020-01-23 10:44:22 -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
jenkins-bot
b19a78a6c8 Merge "Add @phan-assert-false-condition to ApiBase::dieContinueUsageIf" 2020-01-06 10:39:13 +00:00
jenkins-bot
74aee4ed08 Merge "Use wikimedia/ip-utils 1.0.0 to replace IP class" 2020-01-01 23:55:38 +00:00
James D. Forrester
610954eda6 Use wikimedia/ip-utils 1.0.0 to replace IP class
Adjust use in ApiBase.

Depends-On: I9a172b2bd922c3a62248545906bd9bdfcac03a43
Change-Id: Ie5485b1df9f3886add943ddcf8b0824e87a7f3e4
2020-01-01 02:29:11 -08:00
Daimona Eaytoy
dbf0990447 Avoid PHP scalar type juggling in includes/ (part 2)
Continuation of e5444ea55a.

Change-Id: I9f95e7de4e219dee3abcdd210bb708d949f378d0
2019-12-30 20:57:18 +00:00
Umherirrender
7dffd6a064 Add @phan-assert-false-condition to ApiBase::dieContinueUsageIf
@phan-assert-false-condition $x will make Phan infer that the argument
to parameter $x is falsey if the function returned successfully.

Change-Id: I928474e922980b2759fcc4252b1df21164297e0a
2019-12-22 22:58:16 +01:00
Daimona Eaytoy
598c4d7fcb build: Upgrade phan to 0.9.0
Scalar casts are still allowed (for now), because there's a huge amount
of false positives. Ditto for invalid array offsets.

Thoughts about the rest: luckily, many false positives with array offsets
have gone. Moreover, since *Internal issues are suppressed in the base
config, we can remove inline suppressions.

Unfortunately, there are a couple of new issues about array additions
with only false positives, because apparently they don't take
branches into account.

Change-Id: I5a3913c6e762f77bfdae55051a395fae95d1f841
2019-12-07 20:16:19 +00:00
Daimona Eaytoy
b5f0d61ee4 Fix new phan errors, part 8
Bug: T231636
Change-Id: I61852ba55362ab9ae8cc8c1ab6b27565ce1d08e7
2019-10-22 10:09:13 +02:00
Max Semenik
bdf7e3f5bd Set constant visibility, part 1
Change-Id: I3dad26b1a0bd469fa84fee5c15d9b581765ceb94
2019-10-18 02:19:24 +00:00
Umherirrender
c722875c07 Use real varargs in ApiBase class
Change-Id: I7419fc690c5291ad511b67f4ab6e96afde480238
2019-10-11 20:11:59 +02:00
jenkins-bot
66d647b893 Merge "Highlight internal modules in API help and sandbox" 2019-10-11 14:48:01 +00:00
Lucas Werkmeister
3983e1af46 Highlight internal modules in API help and sandbox
This mostly mirrors the existing handling for deprecated modules. In
lists, internal modules are ordered after deprecated ones, with
deprecated internal modules at the very end.

action=paraminfo gains an array of internalvalues analogous to
deprecatedvalues. Help messages for internal modules are prefixed with
the text “Internal”. The help page and API sandbox styles color internal
values in red, just like deprecated values (and matching the existing
style for the “this module is internal or unstable” warning in the help
page), but do not add a strikethrough.

Bug: T185508
Change-Id: I5dfc3bacbc070d74f467eb1a4042cab159aa28ec
2019-10-11 16:30:16 +02:00
Daimona Eaytoy
69cadf44a9 Unsuppress PhanParamsTooMany
This is the last repo-wide suppressed issue. Hurrah.

Bug: T231636
Change-Id: I3dc939f115bea14848c9c40bc52a7601f86ca0a7
2019-10-10 12:44:08 -07:00
Umherirrender
268346e562 phan: Enable PhanTypeMismatchArgument issue
Bug: T231636
Depends-On: I5de4f8f32a47c3f41c990ffe2ebd091fc23d1a58
Change-Id: I34d65fe3ff1916f2af675f0b1f19641b0cdfadc0
2019-09-19 20:11:42 +02:00
jenkins-bot
28d9e60182 Merge "Stop mangling $_GET and provide WebRequest::getQueryValuesOnly()" 2019-09-06 17:38:26 +00:00
Tim Starling
0c0676c34e Stop mangling $_GET and provide WebRequest::getQueryValuesOnly()
I doubt there was ever a good reason for mangling $_GET to add the
title, this was just b/c for the sake of b/c. It was formerly used in
core but that was so long ago that I doubt there was any usage in
extensions at the time. Now there is one usage of $_GET['title'] in an
unmaintained extension, but it was only added in 2017.

Also I added WebRequest::getQueryValuesOnly() which is an interface to
the unmodified $_GET. The motivation is allowing OAuth to work with the
REST API, since OAuth needs an unmangled view of $_GET for signature
generation. The Action API gets around the problem with a special hack
in interpolateTitle(), disabling it for the Action API only.

A review of callers of getQueryValues() suggests that many would
benefit from using getQueryValuesOnly() instead. But I only changed it for
callers in api.php and thumb.php since the effect of the change there is
certainly beneficial, whereas callers under index.php may possibly be using
the path parameters to construct self-links.

Rest\RequestFromGlobals uses $_GET directly, which means that this
change causes it to not return PathRouter matches as GET parameters
anymore.

Change-Id: Ic469577fae17c0b1ac69466df7bc9f03e61c74e3
2019-09-05 15:00:28 +10:00
jenkins-bot
d4e0dbcf96 Merge "ApiBase: Always validate that 'limit' is numeric" 2019-09-04 15:15:43 +00:00
Bartosz Dziewoński
a9199bf854 ApiBase: Always validate that 'limit' is numeric
Bug: T231582
Change-Id: I956d4d623bfeace1b542039283e04a970fd40121
2019-09-04 00:27:12 +02:00
Daimona Eaytoy
e70b5b3309 Unsuppress other phan issues (part 4)
Bug: T231636
Depends-On: I58e67c2b38389df874438deada4239510d21654f
Change-Id: I6e5fba7bd273219b1206559420b5bdb78734aa84
2019-08-31 17:13:39 +00:00
Petr Pchelko
fd130247c2 Deprecate and replace usages of User:isAllowed{All,Any}
Bug: T220191
Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2
2019-08-21 18:36:16 -07:00
Umherirrender
2664eeb632 Clean up spacing of doc comments
Align the doc stars and normalize start and end tokens

Change-Id: Ib0d92e128e7b882bb5b838bd00c74fc16ef14303
2019-08-05 22:29:50 +00:00
Thalia
55ebd6ad58 Fix API message maps for block errors
* Add composite block error message key to ApiBase
* Fix partial block error message key to point to partial block API
  error message key
* Add partial and composite block message keys to ApiMessageTrait

Bug: T227167
Bug: T227168
Change-Id: I5c354d2f038c5b02837268584eb43750a9ebb712
2019-07-03 08:05:27 +01:00
James D. Forrester
a4d976fc83 ApiBase: Drop get(Examples|(Param)?Description(Message)?)\(\), deprecated since 1.25 and 1.30
Change-Id: Ie62436692f39825237d36002aa01bedf1caa1fa3
2019-07-01 14:05:00 -07:00
Máté Szabó
a88f1d6b58 API: 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 API classes.

Bug: T220191
Change-Id: I768d07a520ca6473a4eefb88c9f587657bc74357
2019-05-30 20:23:53 +02: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
Thalia
2843213120 Fix AbstractBlock param types in documentation
Change-Id: I503375485956d3c05da445542419fb62684ae34a
2019-05-14 13:42:50 +01:00
jenkins-bot
cb79b0207e Merge "Restore ApiQueryUserInfo::getBlockInfo() as a stub." 2019-05-11 09:42:28 +00: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
Derick Alangi
1981823755 Remove several methods, deprecated in 1.32
I've checked and doubled checked that these methods are no longer used
anywhere in core or extensions, hence removed them. They were hard deprecated
in MediaWiki 1.32.

* OutputPage:
  ** `::showFileCopyError()`
  ** `::showFileRenameError()`
  ** `::showFileDeleteError()`
  ** `::showFileNotFoundError()`

* ApiBase:
  ** `::truncateArray()`

* IcuCollation:
  ** `::getICUVersion()`

* HTMLForm:
  ** `::setSubmitProgressive()`

* ResourceLoaderStartUpModules:
  ** `::getStartupModules()`
  ** `::getLegacyModules()`

* BaseTemplate:
  ** `::msgHtml()`

* QuickTemplate:
  ** `::msgHtml()`

* WatchAction:
  ** `::getUnwatchToken()`

Bug: T220656
Change-Id: Ic1a723a991f4ff63fcb5f045ddcda18d1f8c3c68
2019-05-09 11:36:44 -07:00
Thalia
824655f3b7 Separate Block into AbstractBlock, Block and SystemBlock
This commit splits the existing Block class into AbstractBlock, Block
and SystemBlock.

Before this patch, the Block class represents several types of
blocks, which can be separated into blocks stored in the database,
and temporary blocks created by the system. These are now
represented by Block and SystemBlock, which inherit from
AbstractBlock.

This lays the foundations for:
* enforcing block parameters from multiple blocks that apply to a
user/IP address
* improvements to the Block API, including the addition of services

Breaking changes: functions expecting a Block object should still
expect a Block object if it came from the database, but other
functions may now need to expect an AbstractBlock or SystemBlock
object. (Note that an alternative naming scheme, in which the
abstract class is called Block and the subclasses are DatabaseBlock
and SystemBlock, avoids this breakage. However, it introduces more
breakages to calls to static Block methods and new Block
instantiations.)

Changes to tests: system blocks don't set the $blockCreateAccount or
$mExipry block properties, so remove/change any tests that assume
they do.

Bug: T222737
Change-Id: I83bceb5e5049e254c90ace060f8f8fad44696c67
2019-05-07 17:36:31 -05:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02: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
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
Kunal Mehta
4ef179e335 Fix/suppress misc phan errors (#5)
Add lots of missing return statements, or remove incorrect doc blocks.

Change-Id: I0881e98fbb9d0d4cf79ecc824064d24538055d3f
2019-04-05 15:53:37 -07:00
Brad Jorsch
0ccc692012 API: Avoid duplicate logs to api-feature-usage
It can wind up logging deprecations twice if extractRequestParams() is
called with different values for 'parseLimit', for example.

Change-Id: I921777089fb8cfb4339af6fd08ee3475ed31b7f6
2019-03-05 17:56:55 -05:00
Brad Jorsch
426df4cd70 API: Handle Messages in errorArrayToStatus()
Two bugs here:
* If the error array contains an entry using a Message object instead of
  a string as the key, it'll blow up trying to do
  `self::$blockMsgMap[$error[0]]`.
* If the error array contains a Message object not wrapped in an array,
  it'll blow up trying to do `...(array)$error`.

Bug: T217382
Change-Id: I2a08e02bca0fb194416b3f2e6a1d6192d5c13cb2
2019-03-01 09:53:01 -05:00
Brad Jorsch
6a28fb3ace API: Use log context for api-feature-usage log
The text message is deprecated.

Bug: T217162
Change-Id: Ie891257140ea19369e10b2e91463a1fb4aa5d233
2019-02-27 17:06:02 -05:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
Brad Jorsch
c073e531cf API: Spread autoblocks from action=edit and action=move
The code in EditPage and SpecialMovepage does this primarily in web UI
code paths that aren't called by the API. EditPage also has a check in
the internal code path used by the API, but ApiEditPage runs its own
permissions check first and won't reach that code path.

Bug: T216245
Change-Id: I6263c8b60a24f3195dba583463f1ce4b004f82f5
2019-02-19 17:34:48 -05:00
Brad Jorsch
ace0338421 API: Add block info to more block errors
When using ApiBase::errorArrayToStatus(), block info was added to
'blocked' errors. But when using dieStatus() with a Status object
returned by core MediaWiki code, block info was not being added.

Change-Id: I14887b6dd76d665055283945b956b2e26c521ed5
Depends-On: Ie3addf53ab5fabf1c24e1033b58e63927f4e21bf
2019-02-19 17:34:48 -05:00
Brad Jorsch
94110916b1 API: Don't return a deprecation warning for default values
If a deprecated parameter has a default value, or a deprecated value is
part of the default value for a parameter, don't give the client a
deprecation warning about it.

Bug: T215548
Change-Id: I980763e3d44fb1b7459c64b175fcaddf5fd44a13
2019-02-07 15:32:36 -05:00