Commit graph

1681 commits

Author SHA1 Message Date
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
MusikAnimal
9d3254d18e OutputPage: add @internal annotation to addHtmlClasses()
Follow-Up: I4b994e081d9582801fe9d198efd68afc46a14703
Change-Id: I938bfc21d38981c307a87889ef353ddd21a04791
2020-05-26 18:15:02 +00:00
suecarmol
b32e71aa60 Ajax watch: Move JS config var to packageFiles
To improve performance, the watchlist expiry flag was moved to
packageFiles instead of the OutputPage.php file

Bug: T249259
Change-Id: If57030db7d1e90b0890ee2a1ad466772a2f8b8bc
2020-05-22 19:21:45 -05:00
MusikAnimal
168e23e80a OutputPage: fix @since version
Change-Id: I1880ed04237cadec5ea9e3abde15b21d004208f8
Follow-Up: I4b994e081d9582801fe9d198efd68afc46a14703
2020-05-13 17:12:29 -04:00
suecarmol
6224ffd03c Replace toast with OOUI popup on watchlist message
When watching a page, a toast appears with a message to confirm it has been
watched/unwatched successfully. This replaces the toast with a OOUI popup.

Bug: T249259
Change-Id: Ib1b8e31ce8e6fe271cb0d6e5fbaf80bc65360da1
2020-05-06 19:53:22 -05:00
MusikAnimal
36d2a5b88f OutputPage: allow additional CSS classes to be added to <html>
In some cases CSS classes must be on the <html> element and not the
<body>. An example is the DarkMode extension. Due to how the stacking
context works, the CSS `invert()` filter must be on <html>. We can't use
JavaScript to apply the styles because there would be a brief delay
after page load before the JS runs, causing a flashing effect.

Bug: T241925
Change-Id: I4b994e081d9582801fe9d198efd68afc46a14703
2020-04-28 11:46:45 -07:00
C. Scott Ananian
85e1525862 Deprecate ParserOptions::getTidy() and ParserOptions::setTidy()
These options no longer have any effect.

Bug: T198214
Change-Id: Icc3eaed7ab8a3070c4339b272d580328ba40912d
2020-04-19 22:53:39 -07:00
Dave Pifke
0a3aa08b72 OutputPage: Add experimental preconnect resource hint for thumbnails
Adds <link rel="preconnect"> for the first valid foreign or local file
repo, on pages containing images.

This is a hint to the browser that it should open a connection to the
other host (e.g. upload.wikimedia.org), if it doesn't have one
already.  Doing so allows the connection setup to happen before page
parsing is complete, and should result in faster image loading,
especially on slow connections.

Bug: T123582
Change-Id: I2dcc14f05012570a3e41ed8c7064969a4cbfb6db
2020-04-07 21:04:47 +00:00
Thiemo Kreuz
1006aa41e6 Fix mismatching type hints in PHPDoc tags
This is a collection of random bits from my local stashes. This patch
intentionally only touches comments, no code.

Notably:
* Use more specific string[] instead of array, if possible.
* Some comments mention "or null", but miss to list the type.

Change-Id: I712b28964f125c8e3dcb4e3fb993757a09f96644
2020-03-24 09:59:02 +01:00
Roan Kattouw
f160f71823 OutputPage: Fix warning when setting wgUserNewMsgRevisionId
Follow-up to e08e9609ff, which contained a
typo ($$ instead of $)

Bug: T248049
Change-Id: I7206cb61a61cad528ece880cffcbdd7b4e04e935
2020-03-18 20:27:14 -07:00
Timo Tijhof
e1c88d2fcb resourceloader: Merge 'user.tokens' module into 'user.options'
For back-compat, keep 'user.tokens' as deprecated alias to 'user.options'
for one release cycle (to be removed in MW 1.36).

== user.options ==

As before, 'user.options' arrives immediately on every page view,
embedded in the HTML. It has an async dependency on 'user.defaults',
which is not downloaded until there is a known demand on
'user.options'. Once that arrives, the implementation closure
of 'user.options' will execute, and the module becomes 'ready'.

== user.options "empty" ==

Before this change, UserOptionsModule used isKnownEmpty to consider the
module "empty" for logged-out users (as well as for logged-in users that
haven't yet set any preferences).

This was a mistake. It is invalid in ResourceLoader to mark a module as
"empty" if that module has dependencies (see also T191596 and c3f200849).

This broke the state machine. The impact was minimal given that it is unlikely
for features to read keys from mw.user.options for logged-out users, which
if attempted would have simply returned null for all keys.

== New HTML ==

The user.options module is always embedded (never empty), and always
has a dependency on user.defaults.

== Cached HTML ==

The cached HTML for anons sets user.options's state to ready without
waiting for any dependency. Per the above, this was already causing
subtle bugs with mw.user.options.get() likely returning null for anons,
which was fairly innocent. For tokens a bottom value of null would be
problematic as the default for tokens must be "+\" instead. To make
sure that is available for cached page views, set this directly
in mediawiki.base.js. The cached HTML does contain an implement call for
'user.tokens' that contains the same defaults, but new code will not
be asking for or waiting for user.tokens, so that is unused.

Bug: T235457
Change-Id: I51e01d6fa604578cd2906337bde5a4760633c027
2020-03-17 20:51:15 -07:00
Timo Tijhof
e08e9609ff OutputPage: Only export wgUserNewMsgRevisionId if non-null
Bug: T53640
Bug: T233676
Bug: T231168
Change-Id: Ia4f07bb90e6ed029d87947e7cf62c5a5d69726e9
2020-03-13 22:27:13 +00:00
Timo Tijhof
490d5c7acd OutputPage: Remove 'wgMonthNamesShort' from mw.config
This internal variable was exported on all page views for all users
for use by jquery.tablesorter.

This feature has not used it since 2013 (commit 65f11938e8),
where it was migrated to use the mediawiki.language module instead.

Bug: T48496
Bug: T219340
Change-Id: I1c9b012d633ffd76a31be5822fd2f4f984e1fb5c
2020-03-13 20:45:20 +00:00
Brian Wolff
89be2c5820 Allow storing additional CSP sources in ParserOutput
This adds methods to ParserOutput ::addExtraCSPStyleSrc,
::addExtraCSPDefaultSrc, and ::addExtraCSPScriptSrc, to easily
allow parser tags/functions to add additional CSP sources if their
tag needs it. Previously such an extension would need to use
and OutputPage hook. This is modeled on how addModules() works.

The immediate use case is for Kartographer (T240960), although
its expected that lots of extensions might do something like this,
especially extensions used outside of Wikimedia.

Change-Id: I24e5f0b4edff58025a0c2a3e1a9aa3f62eb7db7b
2020-03-12 17:39:51 -07:00
Daimona Eaytoy
a3a620a1bd Remove $options parameter from OutputPage::parserOptions
No callers passing a parameter
https://codesearch.wmflabs.org/search/?q=-%3EparserOptions%5C(%5B%5E%5C)%5D&i=nope&files=&repos=
and no dynamic calls AFAICS.

Change-Id: I526b1e8e310c1ad3d14402b67e6c967923f3609f
2020-03-08 14:23:26 +01:00
Brian Wolff
505e10345d Allow adjusting CSP headers from BeforePageDisplay hook
Previously this hook ran after the header was sent, so it was
very confusing why CSP adjustments were being ignored by it. This
was especially the case, as it is a very natural point to adjust
the CSP policy, as commonly it is used to adjust what modules are
loaded.

Bug: T246614
Change-Id: I38f8f43fdc1d9bbd2f9af04305aad7a370b107b6
2020-03-02 01:14:49 -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
jenkins-bot
ab7028b9b5 Merge "Replace calls to Title::getUserPermissionsErrors (part 5)" 2020-02-26 03:28:16 +00:00
DannyS712
909f0bef6e Replace calls to Title::getUserPermissionsErrors (part 5)
This does //not// fix all calls in core.

Bug: T244929
Change-Id: I02ffcca31fa0bdc6bffddf21e82f4ff5e9ab5374
2020-02-26 03:00:33 +00:00
Timo Tijhof
f575721a06 Update all use of $wgVersion to MW_VERSION
Follows-up I04628de4152dd5.

Bug: T212738
Change-Id: I718474ec0d9fd29ac2c05477f0f2493615d8aff5
2020-02-25 02:16:12 +00:00
C. Scott Ananian
1aef5d72d9 Remove deprecated non-tidy OutputPage::parse/parseInline methods
The non-tidy parsing modes were deprecated in 1.32.  Remove the
deprecated parse/parseInline methods which use them, as part of a
general clean up of nontidy parsing modes.

Bug: T198214
Change-Id: I04ea82dd20eac8b0ce07a8d0e6b0bf2c4b03dbe8
2020-01-15 16:22:19 -05: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
ec34c3a340 Merge "Add get{Robot,Index,Follow}Policy methods to OutputPage" 2019-12-29 01:16:03 +00:00
Jack Phoenix
d310b5f9cf OutputPage: Make the DB replica lag warning CSS classes greppable
mw-lag-warn-normal and mw-lag-warn-high.

Change-Id: I92c5cba64059a42d1b325858debf10e0fc33dc85
2019-12-14 20:24:48 +00:00
Jack Phoenix
730f7b5917 Add get{Robot,Index,Follow}Policy methods to OutputPage
Inspired by wikiHow's RobotPolicy extension, which depends on the existence of OutputPage#getRobotPolicy, as the extension needs to know the current robot policy state.

Change-Id: I764f5584a9f04a6b66c53193e9118dd1a5248284
2019-12-11 14:23:51 +02:00
jenkins-bot
9d8954a372 Merge "build: Upgrade phan to 0.9.0" 2019-12-09 16:15:27 +00:00
Daimona Eaytoy
ce0856b12f Fix more scalar types in docblocks
Change-Id: I574d4e261ab986e028c3ce26c4f0ec648b88a2ac
2019-12-08 17:59:08 +00: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
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Timo Tijhof
ae08640853 OutputPage,ResourceLoaderStartupModule: Separate internal from public config vars
Change-Id: Ic54d3b36fb379d77139b21b46db7da9f78869e37
2019-10-31 19:35:45 -07:00
Brian Wolff
67ea4f5747 Mild refactoring of ContentSecurityPolicy
This is to make it behave in a more object orientied way. The
goal is to make it be easier to allow extensions to mark certain
pages as requiring a different policy (For example, CodeEditor
extension uses a blob: url with a WebWorker. We don't want to
include that on the policy of every page, but allow the extension
to mark it as required whenever needed).

This commit does not change code behaviour in any way.

Change-Id: I4bf53dabb6e6c5446cea99a64db68b300cef2fd4
2019-10-28 09:02:14 -07:00
jenkins-bot
089e1abb9e Merge "resourceloader: Lower severity of targets violation back to DEBUG" 2019-10-16 21:30:24 +00:00
Krinkle
b8e51a65a9 resourceloader: Lower severity of targets violation back to DEBUG
This reverts commit cb6a24d3c4. We were looking to find
violations other than the Gadgets extension in preparation for
removal of this feature. And... we have. And they're sufficiently
high-volume that it doesn't make sense to keep enabled until we've
fixed those.

Lower the detection severity back down until we've fixed these
new ones.

Bug: T235711
Change-Id: Ia3c047f76430584dcc49741ba2d7b7f7b2b89063
2019-10-16 21:14:46 +00:00
jenkins-bot
7435150c00 Merge "resourceloader: Bump severity of targets violation to WARNING" 2019-10-11 21:25:23 +00:00
Timo Tijhof
cb6a24d3c4 resourceloader: Bump severity of targets violation to WARNING
Now that we've all known violations we can safely enable this
in production. It was mainly held back because the Gadgets
extension violated it "by default" due to not checking targets
and letting core handle it. This has been fixed by f59eaacb4f72d8
in MobileFrontend and 2008def8063 in Gadgets.

Bug: T127268
Change-Id: I43aed5011f96160565f2dfc3422034d0e8fa95c4
2019-10-11 21:10:56 +00:00
Umherirrender
fba5bbe5cd Use real varargs in OutputPage
Change-Id: I24821df0299d18a81e89d2e10671937f65c88bd8
2019-10-11 20:17:48 +02:00
jenkins-bot
ec440ce1bf Merge "Make max-age configurable for logged-out users" 2019-10-03 22:13:50 +00:00
Gilles Dubuc
ea9cb5ceaa Make max-age configurable for logged-out users
For small wikis. When a CDN is present, the value is
overwritten by the CDN.

Bug: T231184
Change-Id: I45a53571d0f5f6316eb97b396c18c0b224586526
2019-10-03 21:59:10 +00: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
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
5d16571ffb Merge "OutputPage: Add visibility to various methods & do some micro-optimizations" 2019-09-15 16:41:21 +00:00
Derick Alangi
f7eede1191 OutputPage: Add visibility to various methods & do some micro-optimizations
Methods that visibility was added to are; `addMeta()`, `addLink()`,
`setCanonicalUrl()`, `addScript()`, `getHeadItemsArray()`, `addParserOutput()`,
`getCacheVaryCookies()` and `haveCacheVaryCookies()`. Last but not lease, did
a few micro-optimizations to `addMeta()` and `addLink()`.

Change-Id: I94d037a5edc7131627724fd1d864000128077b0c
2019-09-15 16:18:12 +00:00
Daimona Eaytoy
3439c00073 Suppress PhanUndeclaredProperty for custom properties and phan bugs
And remove the issue from the exclusions list.

Bug: T231636
Change-Id: Iee73ddb554e354abe52d13dcfc453f9a15bb8877
2019-09-14 13:22:54 +00:00
Thiemo Kreuz
1fa42d25ec output: Narrow Title type hint to LinkTarget
The code never needs a full Title object, but only what the (more
narrow) interface provides.

Change-Id: I3a7aa35c7e90fffaf37f4cb444549237c20e0bd9
2019-09-13 11:34:33 +02:00
Timo Tijhof
cd6707ca18 Remove support for wgUseESI
Experimental feature deprecated since 1.33 (d63684a064).

Change-Id: I9bab4ad1cd1f2c80a3dfcccdf99ed011c9c8a440
2019-09-08 05:11:57 +01:00
jenkins-bot
543c5c1a1f Merge "resourceloader: Compile documentElement.className server-side" 2019-09-03 21:04:23 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00: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
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
Petr Pchelko
f1914810a7 Remove usages of Title::quickUserCan
Change-Id: Ifa53e0ec800e23dc4184d133a100fb9378dfee9e
2019-08-29 11:48:30 -07:00