Commit graph

58 commits

Author SHA1 Message Date
Umherirrender
769bdbf091 docs: Fix nullable documentation for class properties
Change-Id: I6d0577124d852103f485ffdc819876a13f6641c3
2021-09-24 00:54:53 +00:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Timo Tijhof
245bdafd9e resourceloader: Add wikimedia/minify package and remove local copies
- JavaScriptMinifier: The public interface for this internal class is
  ResourceLoader::filter which, except for one caller (minify.php)
  is indeed consistently used already, no other callers need replacing.

- CSSMin: Idem for minification, however, this class has some other
  method as well, which have a number of internal users, but none
  outside core. These have all been replaced in this commit.

- Remove pear/net_url2 as own dependency as this was only used by CSSMin
  and recently added there. This is now a dependency of wikimedia/minify
  instead. This was not part of the public API and no longer mentioned
  here in composer.json or RELEASE-NOTES. (It remains pinned in
  mediawiki-vendor, however.)

Bug: T273247
Depends-On: Iadff8c2112d5e53bd994ab4882006e8c644a2379
Depends-On: Id3c6dcc0b952a9efe34b3a9ed88b716101a51f87
Depends-On: I589be910f57289fd908b22db87241b0e52da60d4
Change-Id: I8d71fc64aeecdb31db218b02e361ae9bb0d19b48
2021-02-24 21:03:02 +00:00
Timo Tijhof
91c73f6bac resourceloader: Add some typehints and misc clean up
* Add a void return hint to methods that are not meant to return
  anything. This helps catch accidental return statements in the
  future, lets Phan better understand how methods are meant to be
  used, and might also allow PHP to better optimise the compiled
  code form (speculation).

  I did not, however, add it to publicly extended methods as that
  might mess with strict mode.

* Remove the internal getResourceLoader() method from MessageBlobStore.
  This has been redundant since 3edaa0b37c.
  The method was protected, and not considered stable to subclass
  for extensions. Hence not a breaking change.

* Add Throwable typehint to formatException() and friends.
  This is the narrowest one I could add given that the methods
  called from here already enforce the same typehint.
  Update the doc to match for now. There isn't a reason right now
  to limit this only to Exception, and given this is the method
  and not the catch statement itself, does not change behaviour.

* Remove unused ResourceLoader->getHookContainer().
  Added within 1.35 cycle, safe to remove.

* Remove unexpected `@since` for `@internal` getHookRunner().

* Remove redundant `@internal` from ResourceLoaderMwUrlModule
  methods, which itself is already `@internal`.

Change-Id: I68d33ff6feca7ef95282a7ff03eb9332adfde31c
2020-07-02 03:05:59 +01:00
Daimona Eaytoy
b1a5367ec8 Fix new phan errors, part 7
Bug: T231636
Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
2019-10-21 22:10:20 +00:00
Fomafix
a9823d16f6 resourceloader: Add array type hints
Change-Id: I4844eae68e85adc46e52646ea066b459bbabdcce
2019-10-05 15:26:56 +00:00
Timo Tijhof
172de0b957 resourceloader: Add version to ResourceLoaderImage urls for long-cache
The code previously here did not work well as it merely forwarded the
hash from the current web request. This had numerous issues:

1. It was often null because requests for stylesheets do not cary
   a version hash.
2. When requested by JavaScript, the version hash would be a
   combination-hash of many unrelated modules, thus when requested as
   part of different batches, it would produce different urls which
   is not ideal.

The impact of this is minimal currently because we basically never use
these urls, as SVGs are almost always embedded instead of ref'ed by url.
PNG urls are only generated for non-JS modules and then only used in older
browsers not supporting SVG. And, even after all that, for the edge case
of an SVG being ref'ed by url, they would be stored in LocalStorage by
mw.loader with the name+version of the module the image belonged to, not
the version hash of the batch request it came with.

Which means that, yes, localstorage key for "somemodule+someversion" would
have different values for different users, based on which batch the value
came with, because the image urls were using the version hash of the batch
request from ResourceLoaderContext. This is weird, but didn't cause bugs
or inefficiencies because the user would never be exposed to the other
possible urls for that image because we always check LocalStorage first.
It did cause fragmentation server-side in Varnish, though.

This is all fixed now by always including a version, and setting it to
the version of the module. This means there is no more Varnish fragmentation
for these. And it means that browsers are now allowed to cache the images
served from these urls for 30+ days (immutable) instead of only 5min,
which is what happened when they didn't have a version parameter (or set to
null).

Bug: T233343
Change-Id: I4af7fda03698ed4c288d154e7787fb2f3cbbe6c5
2019-09-28 02:06:32 +01:00
Timo Tijhof
a5ce1d7792 resourceloader: Add Doxygen group and improve overall docs
* Add license header where missing.
* Add missing `@since` (1.17 for most classes), except
  ResourceLoaderLessVarFileModule since 1.32 (1bc62c548c).

* Remove duplicate file-level description for class-only files,
  merge with the class description instead.

* Remove my own `@author` annotation from one file.

* Mark core's own FileModule subclasses as `@internal`, except
  for the following which we support use of in extensions:
  ResourceLoaderLessVarFileModule,
  ResourceLoaderOOUIIconPackModule, and
  ResourceLoaderWikiModule.

Change-Id: I336af2e4ccdbe2512594e8861b72628d24194e41
2019-09-14 18:37:36 +00:00
Bartosz Dziewoński
77f4bab8b7 Allow skins/extensions to define custom OOUI themes
This change follows I39cc2a735d9625c87bf4ede6f5fb0ec441d47dcc.

docs/extension.schema.v1.json
docs/extension.schema.v2.json
includes/registration/ExtensionProcessor.php
* The new extension attribute 'OOUIThemePaths' can be used to define
  custom OOUI themes. See I9187a63e509b601b8558ea82850fa828e5c8cc0a
  for an example usage.

includes/resourceloader/ResourceLoaderOOUIModule.php
* Add support for 'OOUIThemePaths'.
* Defining 'images' is now optional. I figure custom themes are
  unlikely to have or need them.
* Use ResourceLoaderFilePath objects to allow skin-/extension-defined
  OOUI module files to use skin/extension's base paths.
  This was previously used to support $wgResourceModuleSkinStyles,
  but only for 'skinStyles' - now ResourceLoaderFileModule needs
  to also handle it for 'skinScripts', and ResourceLoaderImageModule
  for 'images').

includes/resourceloader/ResourceLoaderFilePath.php
* Add getters for local/remote base paths, for when we need to
  construct a new ResourceLoaderFilePath based on existing one.

includes/resourceloader/ResourceLoaderFileModule.php
includes/resourceloader/ResourceLoaderImageModule.php
includes/resourceloader/ResourceLoaderOOUIImageModule.php
* Add or improve handling of ResourceLoaderFilePaths:
  * Replace `(array)` casts with explicit array wrapping, to avoid
    casting objects into associative arrays.
  * Use getLocalPath() instead of string concatenation.

tests/phpunit/includes/resourceloader/ResourceLoaderFileModuleTest.php
tests/phpunit/includes/resourceloader/ResourceLoaderImageModuleTest.php
* Some basic checks for the above.

Bug: T100896
Change-Id: I74362f0fc215b26f1f104ce7bdbbac1e106736ad
2019-07-10 22:08:14 +02:00
Umherirrender
9fa4b4ebdb resourceloader: Fix return type in ResourceLoader-related classes
Change-Id: I543e321129cf8fadc1159017b622528f462ea116
2019-06-18 20:20:34 +00:00
Bartosz Dziewoński
b8b8a3c692 ResourceLoaderOOUIIconPackModule: Always use MW core 'localBasePath'
Otherwise, extensions defining icon pack modules in extension.json
would need to specify "localBasePath": "../..", which is silly.

Follow-up to a8dae2212c.

Change-Id: If8f02867955d649c809b6b41de0f77e594b633d6
2019-06-12 00:56:32 +02:00
Derick Alangi
6aed4cefdc resourceloader: Fix return type doc for getSelectors() method
So I've checked and this method should return an array and this array
specifically is an array of strings (string[]). In addition, remove an
irrelevant semicolon after foreach().

Change-Id: Id7dffe882583a7555d87a5b9c409584478c30a8c
2019-04-04 11:27:22 +01:00
Umherirrender
fb52474137 Fix is_array check in ResourceLoaderImageModule
Checking the variable used as expression in the foreach seems wrong.
Also the var is already checked before, so this is the wrong var name

Change-Id: Ia2a7352422ace1e78949a2009b0ad1f16681fc74
2019-02-28 21:06:53 +01:00
Umherirrender
6efe87449f Document type for class properties in ResourceLoaderImageModule
Also declare missing properties

Change-Id: Ia63597fa996e7050b29ff6df0694dd7e036800d8
2019-02-25 21:54:41 +01:00
jenkins-bot
0ada062ce6 Merge "Allow ResourceLoaderImage modules without data URIs" 2018-07-09 14:24:36 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
jdlrobson
36252b71da Allow ResourceLoaderImage modules without data URIs
Bug: T198930
Change-Id: I13853a59222b38de0afde301a781af06067d4ddc
2018-07-06 17:17:34 +00:00
jdlrobson
8faba225fe ResourceLoaderImage module definitions can define a defaultColor
Bug: T197909
Change-Id: I0745e112d11026ed59d8daca990b313305cd094a
2018-06-27 20:36:47 +00:00
Timo Tijhof
a0339862ac resourceloader: Add @covers for FileModuleTest
Add @covers for various helper methods used by public methods, where the helper
methods actually contain most of the logic being tested in FileModuleTest.

I've changed these methods from protected to private (confirmed no usage)
to further pin down that their contract doesn't matter beyond making the
public methods work.

Change-Id: I2aef0d322b38bc3595e7d2c2339112b16fc66b8d
2018-06-26 02:06:03 +00:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
James D. Forrester
1a4ebad8b7 Increase Opera minimum for Grades A and C to 15
This drops into Grade X the Opera versions 12.10+ from Grade A,
and versions 10.x from Grade C.

Bug: T121517
Change-Id: Ie4df9c751bd0250581cd2e25cf1b38e69e67e82f
2017-11-29 02:40:27 +00:00
Bartosz Dziewoński
ad7e98afbb resourceloader: Clarify operator precedence
Change-Id: I478db046a1cc162c6767003ce45c9b56270f3372
2017-10-06 23:14:02 +00:00
Roan Kattouw
995b9ca4e5 ResourceLoaderImageModule: Use CSSMin::buildUrlValue() where needed
We can't just assume that the URLs that we generate are safe to use
in url() without quotes. There's already a function that automatically
uses quotes where necessary, so use that.

Change-Id: I6663e49b82592eb45b8854fcff56ac966b39f8ce
2017-09-14 11:40:02 -07:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02:00
jenkins-bot
e2b2ffac90 Merge "ResourceLoaderOOUIModule: Minor code quality fixes, and more comments" 2017-03-17 20:21:42 +00:00
Bartosz Dziewoński
519d578697 ResourceLoaderOOUIModule: Minor code quality fixes, and more comments
Change-Id: Ibc7195cc68e1a46062612635988bd16d8145ab63
2017-03-17 03:29:29 +01:00
WMDE-Fisch
f4329ddbc8 resourceloader: Use SVG url when ResourceLoaderImageModule can't embed
When the SVG is too big to be embeded it is now included via URL.
Previously it would produce an empty/broken 'url()' value.

Bug: T160532
Change-Id: I158781f9430cfa35737397ac7537a471634c4480
2017-03-16 22:11:11 +00:00
Timo Tijhof
189c906062 resourceloader: Remove unused getPosition() code
Unused as of bc374082fa (T109837).

Change-Id: I1d8f7109bbe49700f1824fdce0439e958e84f6fa
2016-11-18 19:02:12 +00:00
Amir Sarabadani
d56829dca8 Clean up array() syntax from docs, part VI
Change-Id: Ib0eea494e2065c7ab356dc45fd174544a9c1c942
2016-09-12 14:36:37 +04:30
Timo Tijhof
453ada4be7 ResourceLoaderImage: Use hashes for versioning instead of timestamps
Remove use of the deprecated getModifiedTime() method and incorporate
file information in getDefinitionSummary() directly, instead of relying
on the parent class to include getModifiedTime().

Change getDefinitionSummary() to append to the summary instead of
setting arbitrary keys in the array directly to avoid conflicts.
This matches the pattern used elsewhere.

Change ResourceLoaderImage to use file hashes instead of timestamps
to avoid needless cache invalidation. At Wikimedia these modules
tend to roll over every week due to git not storing timestamps.
See also T104950, 9112c9347b, f37cee996.

Change-Id: I5d019bfb991c3b8042d1db14a853ba46cc690315
2016-08-19 00:05:33 +00:00
Bartosz Dziewoński
7136ae9d3e ResourceLoaderImageModule: Mark as style-only
Follow-up to a464d1d41d.

Bug: T87871
Change-Id: Iff307af1cf550c02bea94d596f316b30da259900
2016-08-18 21:00:51 +02: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
Roan Kattouw
2a428a1755 Follow-up 23cfe1bba: harmonize image embedding CSS
23cfe1bba changed ResourceLoaderImageModule::getCssDeclarations(),
but contrary to the documentation did not synchronize it with
mediawiki.mixins.less. This commit does that.

This commit brings the -o-linear-gradient rule back (this time with
a comment that explains why it's there), and removes the
-webkit-linear-gradient rules from mediawiki.mixins.less
and CSS code that copypasted it.

Change-Id: Ia7e9738d90919248748e6968192bf02e420cddd0
2015-12-14 16:00:49 -08:00
Ed Sanders
23cfe1bba6 Remove vendor prefix support for SVG embedding
Also remove the -o- prefix which uses 'fallback', as without
that rule it will use 'fallback' anyway.

Bug: T118815
Change-Id: I6a6e3b24b1cda55dfa9675743c39d21e792275c7
2015-11-17 02:40:05 +00:00
Timo Tijhof
afcfc3290c resourceloader: Consistently refer to the framework as ResourceLoader
Change-Id: Ia59e4eac9662723e80d62f7cfcb9e4292e3ee4de
2015-10-28 03:24:40 +00:00
Timo Tijhof
9435cd81b0 resoureloader: Consolidate styles-only queue at the top
This effectively reverts d6b4d3c537 and declines T97420.
This was previously attempted in b7c0e537eb.

Drop support for position "bottom" for addModuleStyles().
This feature was only recently introduced with the intent
to optimise page load performance, but had an adverse effect.

It increases chances of FOUC due to late discovery of these styles.
It also caused minor problems for some gadgets and extensions
that did not or were unable to set these flags. Some mobile
code was introduced around the same time as this feature and
was never given position=top.

Stylesheets that don't affect initial render or are only needed
on interaction should be loaded via addModules() instead; which
is handled by the asynchronous loader in JavaScript.

Change-Id: Ib9821b7b87cfc8a59062bb6ca358974fdb01ced1
2015-10-27 03:39:34 +00:00
paladox
dca469bb87 Fix phpcs warnings
Bug: T102614
Change-Id: Iecea365f83bbb0c336b58f1cfdebfc9b1112087e
2015-06-18 20:13:37 +00:00
umherirrender
d8821f2b0b Fixed spacing
- Removed space after casts
- Removed spaces in array index
- Added spaces around string concat
- Added space after words: switch, foreach
- else if -> elseif
- Removed parentheses around require_once, because it is not a function
- Added newline at end of file
- Removed double spaces
- Added spaces around operations
- Removed repeated newlines

Bug: T102609
Change-Id: Ib860222b24f8ad8e9062cd4dc42ec88dc63fb49e
2015-06-17 20:22:32 +00:00
Roan Kattouw
2e1916f96d ResourceLoaderImageModule: Fix incorrect documentation
The docs claimed that you had to do something like
'images' => array( 'filename.svg' => array( 'name' => 'foo' ) )
but what you actually need to do is
'images' => array( 'foo' => array( 'file' => 'filename.svg' ) )

Change-Id: Idca2d5c58e4d9fcf008ef5cfe7f8ce77b996c203
2015-06-16 19:37:39 -07:00
Bartosz Dziewoński
c4b6fd313d ResourceLoaderImageModule: Add missing doc stuffs
Follow-up to 1fc57830e2.

Change-Id: I66985fe2edc4d0e92aebcdb39cd56d212fd3270c
2015-06-06 00:38:06 +02:00
Timo Tijhof
64ecc77422 resourceloader: Remove redundant getModifiedTime implementations
Follows-up f37cee996e which replaced the getHashMtime() and
getDefinitionMtime() methods with dummies that always return 1.

These getModifiedTime() implementations were only tracking the
definition summary or custom hash, which is already tracked
by getVersionHash().

Notes:
* SpecialCharacterDataModule: This one was odd as it was tracking
  both the mtime *and* the file contents.

* UserCSSPrefsModule/UserOptionsModule: Remove redundant caching.
  Already taken care of by getVersionHash() as of f37cee996e.

Bug: T94074
Change-Id: I6e37c3c2f85ef4599a8643b0efabc18de2f51ec4
2015-06-03 14:27:38 +00:00
Bartosz Dziewoński
1fc57830e2 OOUI theme support
* Split off OOjs UI's module definitions to a separate file from
  Resources.php.
* Extend ResourceLoaderImageModule to support per-skin images and
  variants.
* Allow skins to specify their preferred OOjs UI theme using new
  skin registry attribute 'SkinOOUIThemes'. The default remains the
  'mediawiki' theme, 'apex' can also be chosen now.
* Implement custom ResourceLoaderOOUIImageModule which implements some
  special sauce required to shoehorn OOjs UI image set definitions into
  ResourceLoaderImageModule with skin-specific styles support.

Bug: T100895
Change-Id: I3fbacbce95126a4cc29221352f3ef846f41e7b1b
2015-05-31 22:55:13 +00:00
Gilles Dubuc
d6b4d3c537 Add ability to load plain CSS files at the bottom
Currently all styles modules added to the page using
addModuleStyles are put into the head, regardless
of their "position" value.

Bug: T97420
Change-Id: Ie4287e17d6f298cc63f42f257b1f67ee36961b77
2015-05-25 21:10:14 +00:00
Bartosz Dziewoński
9bb0c2ac4e resourceloader: Rename ResourceLoaderImageModule::ensureStuffLoaded to loadFromDefinition
The name was a result of my having a bad day when I wrote that code.

Change-Id: I6b729764a963563f0820b8063c3d04f6e676c61e
2015-05-24 11:22:32 +00:00
Bartosz Dziewoński
9e5c3e9521 Use ResourceLoaderImageModule to serve icons for OOjs UI
Benefits:
* Full per-language icons support. Icons that differ for each language
  (such as the 'Bold' icon) will now always display correctly
  according to user interface language, even on old browsers.
* MediaWiki UI icons support. When the 'mediawiki.ui.icon' module is
  loaded, you can use syntaxes such as below to display any OOUI icons
  (from the packs that were loaded) without involving OOUI itself.
    <div class="mw-ui-icon mw-ui-icon-before mw-ui-icon-check">OK</div>
    <div class="mw-ui-icon mw-ui-icon-after mw-ui-icon-check">OK</div>
    <div class="mw-ui-icon mw-ui-icon-element mw-ui-icon-check">OK</div>

Summary of changes:
* Resources.php:
  * Remove icons CSS files. Include image data JSON files instead.
  * Split the images from 'oojs-ui.styles' module to separate ones.
* OutputPage: Update enableOOUI() method for newly split modules.
* ResourceLoaderImageModule: Make it possible to load image data from
  a JSON file.
* update-oojs-ui.sh: Copy source files rather than distribution for
  icon packs.

This is not an improvement when it comes to code quality, though :(
Issues include some nasty code duplication, using "source code" (image
definitions) from OOUI rather than just distribution files, and hacky
methods to load image data from JSON files live.

Bug: T92551
Change-Id: Id369ecaec7048dcf68ba1e4df748362760533782
2015-04-28 13:48:30 +00:00
Bartosz Dziewoński
807c08295a ResourceLoaderImageModule: Implement cache invalidation
Bug: T94733
Change-Id: I6ac2ef8d897813e560daa133b89a7932f8c1a362
2015-04-14 21:31:19 +02:00
Bartosz Dziewoński
2b696972a5 ResourceLoaderImageModule: Remove stupid TODO
Change-Id: I36ade1713b593504a34b1ec92bc4d9e536aa262a
2015-04-01 21:36:08 +02:00
Bartosz Dziewoński
cd73f6e788 ResourceLoaderImageModule: Remove bogus CSSJanus call
We explicitly do not want to use CSSJanus flipping here, as
ResourceLoaderImage has a separate and more sophisticated mechanism
for choosing the right image for given language. This was a no-op,
since there were no flippable paths in the output at this point.

Change-Id: Ieff5f21653504a28afe3d4c110a52d8b06fc6a07
2015-04-01 19:10:03 +00:00
Bartosz Dziewoński
7aeadb7f68 resourceloader: Throw InvalidArgumentException for invalid constructor arguments
(But not for exceptions about missing files.)

Per Legoktm's comments on 8edbfb5feb.

Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb
2015-03-30 19:15:36 +02:00
Bartosz Dziewoński
fca3887393 ResourceLoaderImageModule: Rename 'image' in descriptors to 'file'
Like in OOjs UI. Less confusing. No one is using this yet.

Bug: T93669
Change-Id: Ib1c9af96b46ba660b3697d272129e071da1fdf18
2015-03-29 19:38:14 +02:00