Commit graph

134 commits

Author SHA1 Message Date
daniel
fd2a9bf4a4 resourceloader: Remove Title from public interfaces
Bug: T278459
Depends-On: I9bc371fd299e7a5401ebc1b8d7456d9a4ecde90d
Change-Id: Ib3a0591766f873492ec5a24721e7840f4e1a6407
2021-05-13 10:06:30 +02:00
Timo Tijhof
321f85580b resourceloader: Fix path-only URLs in wiki modules when script path is docroot
When a wiki is installed with its script path as the document root,
then WikiModule would pass MediaWiki's wgScriptPath value (empty string)
to CSSMin as base url, which is invalid.

A similar bug was recently fixed in FileModule with I16abf482e3a1a.

Bug: T282280
Change-Id: I0b9a67aa912eb3a0320631027303cedf3f348bb8
2021-05-08 00:27:50 +01: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
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
929381a81f Merge "Use LinkBatchFactory" 2020-11-01 20:48:02 +00:00
Umherirrender
c85a43561e Improve class property documentation
Reformat existing documentation to match the format

Change-Id: I190b54b5e962f17bab6502dd1b3c02f11dc926d2
2020-10-30 10:38:58 +01:00
Umherirrender
973c562927 Use LinkBatchFactory
Change-Id: Ib82f91048faad8cf8be961d038f30c9261072af5
2020-10-25 23:21:42 +01: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
Umherirrender
5ef28fabf8 resourceloader: Remove truthy check for content
The variable is always truthy here, null values are returning earlier

Change-Id: I9dadcc4be61da39c18fe7836dbb8315b1ccc029c
2020-06-22 22:05:52 +02:00
DannyS712
88b981e831 resourceloader: Use RevisionRecord in WikiModule::invalidateModuleCache
Replace uses of Revision with RevisionRecord; passing a Revision is not
supported anymore, and the method is now marked as @internal.

Decide whether to purge the cache based on the content models of the
revisions' main slots, rather than their formats. The content format
is more difficult to determine on a RevisionRecord than with Revision.
The new interface encourages use of content models instead, so we use
that from now on as well.

Bug: T249561
Bug: T250981
Change-Id: I7ad27f52c0975b0c22f2aa9248c3fcf6d5b2ed8f
2020-06-03 22:39:17 +00:00
Petr Pchelko
1e4beb3107 Hard deprecate Revision::newKnownCurrent
Bug: T246284
Change-Id: Iba93fdeb0a88e6fa4068f03367b23a1f670257c6
2020-03-18 11:52:44 -07:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Timo Tijhof
9c0dee3965 resourceloader: Use ConvertibleTimestamp and Logger directly
Avoid use of wfTimestamp and wfDebugLog global functions.

Also simplify some of the error messages around processing of
'packageFiles' definitions and throw generic LogicException
instead of MWException.

Change-Id: I55ce1f107f53dfdfe673cbe4411b0a7c4e24b2ea
2019-12-04 16:24:40 -08:00
Umherirrender
337ecb0514 Add missing @param and @return to documentation
Change-Id: Ibc5849cc8ea7e7c4eb30ded9c1cfa5f52187c377
2019-11-10 22:12:58 +00:00
Daimona Eaytoy
b5f0d61ee4 Fix new phan errors, part 8
Bug: T231636
Change-Id: I61852ba55362ab9ae8cc8c1ab6b27565ce1d08e7
2019-10-22 10:09:13 +02:00
Daimona Eaytoy
e3412efac3 Unsuppress PhanParamReqAfterOpt, use PHP71 nullable types
These were all checked with codesearch to ensure nothing is overriding
these methods.
For the most part, I've updated the signature to use nullable types; for
two Pager's, I've just made all parameters non-optional, because you're
already forced to pass them with a required parameter at the end.

Bug: T231636
Change-Id: Ie047891f55fcd322039194cfa9a8549e4f1f6f14
2019-10-10 11:53:58 +02:00
Fomafix
0d3b57778c resourceloader: Remove support for $context === null in getContentObj
$context === null is deprecated since 3f1142045f included in 1.32.

Change-Id: I8c13bb0a0ba24c6c999809f650d4f12787a1a9f2
2019-09-23 09:51:45 +02:00
jenkins-bot
552d285184 Merge "resourceloader: Add Doxygen group and improve overall docs" 2019-09-15 19:58:46 +00:00
Umherirrender
f74400487f phan: Disable enable_class_alias_support
It is enabled for b/c in extensions, but not needed in core

Change-Id: I51dca12be9c77049f77563d9bf0edd07928c2300
2019-09-15 08:26:52 +00: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
Timo Tijhof
e9cc45629e resourceloader: Improve ResourceLoaderWikiModule test coverage
* Remove redundant getContent() cases that were all testing the same.
  The redirect logic should indeed be tested, but exists in getContentObj(),
  not getContent(). This test was also mocking getContentObj() thus not
  actually testing what the case claims to test.
  Fortunately, the right test already exists (testGetContentForRedirects),
  so this is redundant.

* Add actual coverage of successful outcomes for getContent (previously
  they were all error/null cases), with JS content, and with CSS content.

* Fix broken test case for "Bad content model". This was not working because
  it mocked out getContentObj, thus it wasn't actually testing "bad content model",
  but rather pointlessly duplicated the previous test case.
  Fix it by actually making it use a WikitextContent object, which makes it
  test the branch that handles incompatible content models.

Change-Id: I59af5318e536c730755352e9be8f995df1f56a86
2019-07-25 23:35:21 +01:00
Derick Alangi
339211a1ea Avoid usage of deprecated Revision::* constants, use RevisionRecord
Change-Id: I872fc89e5c02dd6a3ae9cd7e76640b95dc33f514
2019-07-21 15:03:03 +01:00
Timo Tijhof
253bee13bf resourceloader: Change cache keys to use first segment for grouping by purpose
Remove use of a complete "namespace" for grouping and instead use dashes
within the first key segment for that.

This way, we can leverage the various features WANObjectCache provides
for statistics relating to a particular kind of thing being cached.

These statistics are currently combined for all of resourceloader,
which isn't useful. Mildly related to T223647.

Change-Id: I5df69e46ac436d04e765726a36fc3eb70697a7ed
2019-06-13 18:04:17 +00:00
Timo Tijhof
472d3f4cb4 resourceloader: Remove unused logic for WikiModule::getDB() as null
This was intended at some point for GlobalCssJs but ended up
being implemented differently once we realised that not having
any information about the remote wiki was unacceptable.

The local placeholder that points to metawiki (in case of GlobalCssJs)
must still at the very least be able to query version information
so that it gets a new version hash after changes etc. to ensure
cache rolls over.

This is being removed in preparation for refactoring where
compatibility with this broken model is no longer kept.

Change-Id: I4f1a06ace881daf1a5f202bdba0075460804de57
2019-04-17 19:27:27 +00:00
Timo Tijhof
fa05976f5f resourceloader: Remove needless MW-specific fallback
This is never used by the mw.loader client code. For any
manually crafted requests or fringe usage where the load.php
might be used to fetch some raw JS code that doesn't vary by
language or skin, proceed with qqx/fallback.

In the future load.php might deny these requests and then we
could make this a constructor parameter to ResourceLoaderContext.

Bug: T32956
Change-Id: I4e4ee758cd22278cea9592d4745b4f7fc00e0add
2019-04-15 17:46:41 +00:00
Jack Phoenix
57bfd3d678 resourceloader: Fix variable spacings where need be
This fix is to make sure resource loader code conforms with convension
https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#Spaces.

Change-Id: I34c0a0addbf7c373fc3a64b644a3098bb485a3f4
2019-04-06 13:09:05 +00:00
Aaron Schulz
a26eee40e0 Avoid use of deprecated ObjectCache::getMainWANInstance method
Change-Id: I429e68c8642a00afa812f5ae900c1fb4f8308528
2019-03-01 02:38:55 +00:00
Aaron Schulz
633be72f6f Make invalidateModuleCache() take a database domain ID
Change-Id: I5d9880a5aee4b055365549671258eb9f242a37d6
2019-02-06 12:40:11 -08:00
daniel
c5deaec28c Don't pass false as a wikiId to invalidateModuleCache()
Using false to represent the local wiki is supported in many places in core,
but not in invalidateModuleCache

Bug: T199416
Change-Id: I5cb93c173295261bf5fcf6c77c197a80c4aac1a2
2018-08-03 14:47:29 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
daniel
e8632ab0f6 [MCR] Factor PageUpdater out of WikiPage
This introduces PageUpdater to replace WikiPage::doEditContent,
and DerivedPageDataUpdater, to replace WikiPage::doEditUpdates
and WikiPage::prepareContentForEdit.

See docs/pageupdater.txt for a description of their
functionality.

MCR migration notes:

* The interface of PageUpdater is expected to
remain mostly stable after this patch. Code that has been using
WikiPage::doEditContent can be confidently migrated to using the
new mechanism for revision creation.

* This patch keeps the code inside PageUpdater largely aligned
with the old code in WikiPage, to make review easier to to avoid
mistakes. It is intended to be refactored further, moving
application logic into stateless services.

* DerivedPageDataUpdate is intended as a stepping stone for further
refactoring. Its behavior is designed to be compatible with
callback code that currently relies on
WikiPage::prepareContentForEdit. Much of the code that currently
lives in DerivedPageDataUpdate should be factored out into
services, all behavior relevant to calling code should be exposed
via narrow interfaces.

Bug: T174038
Bug: T196653
Change-Id: If610c68f4912e89af616cdcac1d35a1be3946afa
2018-06-14 13:22:13 +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
Brad Jorsch
3f1142045f Generalize ResourceLoader 'excludepage' functionality
There has long been a hack for previewing edits to user JS/CSS, where
OutputPage would pass an 'excludepage' parameter to
ResourceLoaderUserModule to tell it not to load one particular page and
would instead embed that page statically. That's nice, but there are
other places where we could use the same thing.

This patch generalizes it:
* DerivativeResourceLoaderContext may now contain a callback for mapping
  titles to replacement Content objects.
* ResourceLoaderWikiModule::getContent() uses the overrides, and
  requests embedding when they're used. All subclasses in Gerrit should
  pick it up automatically.
* OutputPage gains methods for callers to add to the override mapping,
  which it passes on to RL. It loses a bunch of the special casing it
  had for the 'user' and 'user.styles' modules.
* EditPage sets the overrides on OutputPage when doing the preview, as
  does ApiParse for prop=headhtml. TemplateSandbox does too in I83fa0856.
* OutputPage::userCanPreview() gets less specific to editing user CSS
  and JS, since RL now handles the embedding based on the actual
  modules' dependencies and EditPage only requests it on preview.

ApiParse also gets a new hook to support TemplateSandbox's API
integration (used in I83fa0856).

Bug: T112474
Change-Id: Ib9d2ce42931c1de8372e231314a1f672d7e2ac0e
2018-04-25 00:37:08 +00:00
jdlrobson
c3f200849b resourceloader: Consider having dependencies as non-empty in WikiModule::isKnownEmpty
If a module itself is empty, it must consider any dependencies
it has before bailing out as empty.

Bug: T191596
Change-Id: I2b45b948a6f78060e53513d3b4b77f48d7bf4a6b
2018-04-24 20:56:32 +00:00
Timo Tijhof
dfb754cbc6 resourceloader: Improve titleInfo docs and simplify title key
* Document the structure of the in-process $titleInfo cache.
  Specifically, specify that it is not the value from getTitleInfo(),
  but rather a container for zero or more versions of such values.
  The reason this is fragmented is because ResourceLoaderContext
  is a parameter to most methods and as such, makes everything
  variable. Tracked as T99107.

* Make various bits easier to understand by consistently refering
  to the container keys as "batchKey", and referring to the internal
  keys as "titleKey".

* Centralise title key logic by moving to private method.

* Replace the internal creation of titleKey to be based on LinkTarget
  with plain namespace IDs and db keys, instead of invoking the
  expensive getPrefixedTitle function which involves quite a lot
  of overhead (TitleCodec, GenderCache, Database, Language,
  LocalisationCache, ..).

Change-Id: I701e5156ef7815a0e36caefae5871524eff3f688
2018-04-10 19:44:40 +01:00
James D. Forrester
6d4e15476c Title: Refactor JS/CSS page handling to be more sane
Change-Id: Ia7837dc614dcc8896a7d4b6d663dc45b6bd4f7ee
2018-02-16 17:35:12 +00:00
daniel
6af796f3e0 MCR: Deprecate and gut Revision class
This is a re-submission of I4f24e7fbb68.

As a first major step towards Multi-Content-Revisions (MCR),
this patch turns the Revision class into a legacy proxy for
the new RevisionRecord and RevisionStore classes.

Backwards compatibility is maintained for all but some
rare edge cases, like constructing a completely empty
Revision object.

For more information on MCR, see
<https://www.mediawiki.org/wiki/Requests_for_comment/Multi-Content_Revisions>.

NOTE: once this is merged, verify create/delete/restore cycle on beta,
      ideally with emulated replication lag.

Bug: T174025
Change-Id: Ia4c20a91e98df0b9b14b138eb4825c55e5200384
2017-12-21 18:08:54 +00:00
Daniel Kinzler
09bf4f5bb2 Revert "[MCR] Turn Revision into a proxy to new code."
This reverts commit 9dcc56b3c9.

With this patch applied, newly created revisions are sometimes not found
just after submitting an edit, until replicas have caught up.

Our best theory is that it somehow interfere with ChronologyProtector,
but we don't have a good idea how.

Also, as legoktm mentioned, the commit message is terrible and needs fixing.

Change-Id: Idf3404f3fa8f8d08a7fb2ab8268726e2c1edecfe
2017-12-19 12:38:48 +00:00
daniel
9dcc56b3c9 [MCR] Turn Revision into a proxy to new code.
Change-Id: I4f24e7fbb683cb51f3fd8b250732bae9c7541ba2
2017-12-18 14:37:29 +00:00
Aaron Schulz
a005f1de98 Clean up wiki ID and DB domain ID handling
Bug: T174017
Change-Id: I42299a393c6691d39817db1d83a176a17df2474b
2017-09-30 10:25:03 +00:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Fomafix
0d247d202a Document return string as JavaScript code for getScript
Change-Id: I01055c2b6a11dbe6284d1aff2352ba428ed9bee2
2017-04-03 10:24:41 +02:00
Timo Tijhof
c505293cfd resourceloader: Improve code coverage for WikiModuleTest
preloadTitleInfo:
* Add missing case for empty $moduleNames.
* Add missing case for invalid page names.

getContent:
* Add missing case for bad title
* Add missing case for dead redirect.
* Add missing case for no content found.

Change-Id: I44dde13cb0db19d91c4ff15a5abefd17353cad90
2017-03-31 18:53:00 -07:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Kaldari
771e85be6c resourceloader: Follow redirects for JavaScript/CSS in WikiModule
Bug: T108653
Change-Id: I9a321fc5728f3bf9df950c060c92e4148cf3ef93
2017-03-14 19:03:26 -07:00
jenkins-bot
17eda64357 Merge "includes: Replace implicit Bugzilla bug numbers with Phab ones" 2017-02-28 00:51:57 +00:00
Timo Tijhof
49948457ec resourceloader: Optimize WikiModule preload for reqs without wiki modules
Currently it was still going through fetchTitleInfo() with an empty array on
the majority of requests without wiki modules, e.g. load.php?modules=jquery.

Bug: T158813
Change-Id: Ie33a2b4da572bb30b2e7a69db07790724ec2f03f
2017-02-22 21:42:16 +00:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +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
Timo Tijhof
baf878fb04 resourceloader: Use cached Revision::newKnownCurrent for WikiModule
Change-Id: I0c68c649783042a959dc20d9675daae790d82cb1
2016-11-07 23:10:24 +00:00