Commit graph

1118 commits

Author SHA1 Message Date
jenkins-bot
3f2937810e Merge "mime: Convert built-in MIME mappings to PHP arrays" 2020-05-21 01:01:06 +00:00
Timo Tijhof
b160ffc27f benchmarks: Remove bench_wfIsWindows.php
This was introduced in r75446 based on r75429. This is not a
benchmark of MW code, but rather a static comparison of how
PHP performs. I'm not sure that's useful to keep long-term.

For what it's worth, anecdotally it seems on PHP 7.2, the caching
might actually be slowing it down. I speculate this might be due
to the simpler variant being easier to optimise, but it hardly
matters as this function now has a very different implementation,
and if something were to call this so often that its runtime
is significant, the caller should probably just avoid doing that
in the first place. Lexical caching tends to be easier to reason
about in the long run, compared to static/unreleased/uncontrolled
caches.

> Running PHP version 7.2.30 (x86_64) on Linux 4.19 (Debian 9 Stretch)
> BenchWfIsWindows::wfIsWindows()
>    count: 100
>     rate: 208464.4/s
>    total:     0.48ms
>     mean:     0.00ms
>      max:     0.01ms
>   stddev:     0.00ms
>
> BenchWfIsWindows::wfIsWindowsCached()
>    count: 100
>     rate: 163266.0/s
>    total:     0.61ms
>     mean:     0.01ms
>      max:     0.05ms
>   stddev:     0.01ms

Change-Id: Iedd273705b88268f1f4d2632913983cbd1028649
2020-05-20 03:33:49 +01:00
Ori Livneh
cb44ddf85b mime: Convert built-in MIME mappings to PHP arrays
Currently, MimeAnalyzer builds the internal mappings of MIME types <=> file
extensions by concatenating several string buffers in mime.type format into a
giant string, and then parsing it. The mapping of MIME types to internal
media types is built up in a similar way, except we use a dubious homegrown
format with undocumented conventions. It's a mess, and an expensive one --
~1.5% of api.php CPU time on the WMF cluster is spent building these buffers
and parsing them. Converting the mappings to PHP associative arrays makes
them much cheaper to load and easier to maintain.

Doing this without breaking compatibility with existing behaviors requires
some delicate footwork. The current mime.types buffer is made up of the
following fragments, in order:

  1) MimeAnalyzer::$wellKnownTypes
  2) If $wgMimeTypeFile == 'includes/mime.types' (sic!):
       the contents of includes/libs/mime/mime.types.
     If $wgMimeTypeFile is another file path (e.g., '/etc/mime.types'):
       the contents of that file.
     If !wg$MimeTypeFile, this fragment is blank.
  3) MimeAnalyzer::$extraTypes (populated by extensions via hook).

The mime.info buffer is built up in the exact same way, except it's
MimeAnalyzer::$wellKnownInfo, $wgMimeInfoFile, and MimeAnalyzer::$extraInfo.

What this means in effect is that some built-in MediaWiki MIME mappings are
"baked in" (anything in MimeAnalyzer::$wellKnown*), and others can be
overridden (anything in includes/libs/mime/mime.*).

To avoid breaking backward compatibility, we have to preserve the
distinction.  Thus this change has two MIME mappings, encapsulated in two
classes: 'MimeMapMinimal', which contains just the baked-in mappings, and
'MimeMap' which contains both the baked-in and overridable mappings.  We also
have to keep the code for parsing mime.types and the ad-hoc mime.info format,
at least for now.

In a FUTURE change (i.e., not here), I think we can:

* Deprecate $wgMimeTypeFile in favor of a new config var,
  $wgExtraMimeTypeFile. $wgMimeTypeFile is evil because if you are using to
  add support for additional MIME types, you can end up unwittingly dropping
  support for other types that exist in MediaWiki's mime.types but not your
  file. The new $wgExtraMimeTypeFile would only be used to add new MIME
  mappings on top of the standard MimeMappings, which was probably the
  original intent for $wgMimeTypeFile.
* Deprecate $wgMimeInfoFile. I don't think we need to provide a replacement,
  because extensions can use the hook, and I doubt anyone is using the config
  var. But if we wanted to provide an alternative, we could have a
  $wgExtraMimeInfoMap that has an array of extra mappings.
* Deprecate MimeAnalyzer::addExtraTypes and MimeAnalyzer::addExtraInfo, and
  provide alternative interfaces that take structured input instead of string
  blobs.

I tested this by dumping the internal state of MimeAnalyzer before and after
this CL using the script in Ib856a69fe, using both default and custom values
for $wgMimeInfo(File|Type).

Bug: T252228
Change-Id: I9b2979d3c9c0dee96bb19e0290f680724e718891
2020-05-19 00:59:52 -04:00
Tim Starling
9f7b735e0f Rename SkinAddFooterLinks to SkinAddFooterLinksHook and add HookRunner method
The interface name is the hook name with "Hook" added.

Change-Id: Ic1e98dfbc9f14938ff75645431bc250a08c337cb
2020-05-18 12:18:36 +10:00
jdlrobson
712312f9cb SkinTemplate: Allow modification of the footer directly
Historically skins like MobileFrontend and  WhoIsWatching rely on
the SkinTemplateOutputPageBeforeExec hook.

I want to deprecate this and allow direct manipulation of the footer
prior to rendering.

The new hook is named SkinGetFooterLinks.

The existing getFooterLinks method is modified. Given this is a new
function, is protected and final and currently has no usages, this
can be done safely.

MobileFrontend: Id83ef2f2cba1dce940f89125b5cd26a29421ee48
Usage in Vector: I4e89beb96f6401ed7e51bafdf0aac408f5a2c42f

Bug: T251817
Change-Id: Id258b1ec2ae7008fc4d586d0647a5131ec889fe6
2020-05-13 15:08:47 -07:00
jenkins-bot
dac0f0de1a Merge "Update hook interfaces for recent additions and deprecations" 2020-05-05 06:56:57 +00:00
jenkins-bot
4d9b4ba5fc Merge "maintenance: Remove maintenance/cdb.php" 2020-05-05 02:14:33 +00:00
DannyS712
b361cf7239 Update hook interfaces for recent additions and deprecations
Changes since the interfaces were generated:
5 hooks added:
* RevisionUndeleted
* ParserBeforePreprocess
* RollbackComplete
* HtmlCacheUpdaterAppendUrls
* HtmlCacheUpdaterVaryUrls

9 hooks deprecated:
* ArticleRevisionUndeleted
* ArticleRollbackComplete (soft deprecation)
* UndeleteShowRevision
* InternalParseBeforeSanitize
* ParserFetchTemplate
* ParserSectionCreate
* ParserPreSaveTransformComplete
* BeforeParserrenderImageGallery
* ParserBeforeTidy

Bug: T240307
Change-Id: Ib91b1d8e519e6cb3c74a6fe174fe2fd0103d6d30
2020-05-05 11:22:04 +10:00
Timo Tijhof
6854834ca4 maintenance: Remove maintenance/cdb.php
There are almost no CDB files left in MediaWiki, and that ones
that remain (commonpasswords.cdb and LCStore support) are
sufficiently large, automated or rarely changed that one wouldn't
be expected to debug them regularly enough to warrant a whole
interactive REPL script dedicated to it.

Note that one can still read these with relative ease using
the eval.php REPL, e.g. using Cdb\Reader::open() and then
calling get($key), firstkey(), or nextkey() etc.

And as of I858dbd5746, a simplified version of this CLI
exists in the wikimedia/cdb library as well.

Change-Id: I20654b91cf15cad512cedeab659ab0dcce5d85f0
2020-05-04 23:36:08 +00:00
Amir Sarabadani
8a4c400412 Introduce maintenance/generateSchemaSql.php
A new script to generate SQL schema from abstract json files.

Bug: T230421
Change-Id: I52f36ed40fc8aac6ff44f046169ae59dbb8f888a
2020-05-04 23:23:19 +00:00
Timo Tijhof
b7ac554304 resourceloader: Move RL hooks to own namespace, use PSR-4
Follows-up f5aaf75ad1.

* Improve some docs for these hooks.
* Add type hints.
* Add them as a subgroup within the ResourceLoader docgroup
  for easy navigation.

Bug: T246855
Change-Id: I52f31e2b63dcf265b27e68ba8fd4f885d82088ac
2020-05-04 22:42:00 +00:00
jenkins-bot
eb88d78c3a Merge "Refactor magic word implementations out of Parser.php" 2020-04-22 08:34:54 +00:00
jenkins-bot
4199c80783 Merge "maintenance: Move FakeMaintenance and LoggedUpdateMaintenance to their own files" 2020-04-21 17:26:59 +00:00
Daimona Eaytoy
870743489b maintenance: Move FakeMaintenance and LoggedUpdateMaintenance to their own files
Originally submitted as commit 2cdeb26d0c.

This patch is fully backwards compatible. The Maintenance.php entry
point is now a true entry point (i.e. no classes defined), and it requires
all the *Maintenance classes.

Bug: T246780
Change-Id: I75b22f54b19fe560ab71349189598245af1c5693
2020-04-21 16:42:01 +00:00
jenkins-bot
cc89a81451 Merge "Automatically generated hook interfaces" 2020-04-21 00:07:41 +00:00
jenkins-bot
1421ca6b65 Merge "Optimize email sending on password reset" 2020-04-20 17:03:09 +00:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10:00
jenkins-bot
260403b83a Merge "Add findBadBlobs script." 2020-04-17 13:32:17 +00:00
daniel
071ce36abd Add findBadBlobs script.
This script scans for content blobs that can't be loaded due to
database corruption, and can change their entry in the content table
to an address starting with "bad:". Such addresses cause the content
to be read as empty, with no log entry. This is useful to avoid
errors and log spam due to known bad revisions.

The script is designed to scan a limited number of revisions from a
given start date. The assumption is that database corruption is
generally caused by an intermedia bug or system failure which will
affect many revisions over a short period of time.

Bug: T205936
Change-Id: I6f513133e90701bee89d63efa618afc3f91c2d2b
2020-04-17 15:04:59 +02:00
suecarmol
632fa50065 Optimize email sending on password reset
Improve performance of sending emails when a user resets a password.

Bug: T247017
Change-Id: I9edb0e4c8845f7a9082035de66f5965c3f9b762d
2020-04-16 13:59:08 -05:00
C. Scott Ananian
37dc40c5df Remove ParserDiffTest
This class was last used in ~2008 as @tstarling was developing the
original wikitext Parser.  It has since code-rotted and wouldn't work
as a drop in for the Parser class any more anyway.  We'll probably
(re)invent something similar when we eventually switch Message
rendering from the legacy parser to Parsoid, but this existing code
isn't a good starting point for that; we'll need to tackle T236812
(splitting Parser into a base class) first.

Last meaningful change to ParserDiffTest:
350b498b9f

Code search:
https://codesearch.wmflabs.org/search/?q=ParserDiffTest&i=nope&files=&repos=

Bug: T236811
Change-Id: I98f1ef8ad296791a810bd8b10343f8640fd23c5e
2020-04-16 14:40:05 -04:00
Niklas Laxström
cdfd1e1891 language: Remove maintenance/language/languages.inc
Nothing uses this file or its classes anymore
according to MediaWiki code search.

Change-Id: Ie165ff887b43304ea519d8b7c0a99a2187a9137e
2020-04-16 16:45:34 +00:00
Niklas Laxström
3af1ef9c0e language: Remove maintenance/language/checkLanguage.php
Translation checks are done in translatewiki.net these days.

Change-Id: I9c9b962a3accc50e875a53cec6ef458e4bb2a6a5
2020-04-15 17:17:07 +00:00
Niklas Laxström
93e06ca81b language: Remove maintenance/language/checkExtensions.php
Broken:
ArgumentCountError from line 43 of /home/developer/mediawiki/workdir/
extensions/Translate/ffs/MediaWikiExtensions.php: Too few arguments to
function PremadeMediawikiExtensionGroups::__construct(), 0 passed in
/home/developer/mediawiki/workdir/maintenance/language/checkLanguage.inc
on line 609 and exactly 2 expected

No point fixing this, checks are done on translatewiki.net side.

Change-Id: I9f39684c2ef8479ea35ad1d60e3f1f86d88a8067
2020-04-15 17:14:35 +00:00
Aaron Schulz
3c7f29a6b9 Add small HtmlCacheUpdater service class to normalize purging code (2)
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).

The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
2020-04-14 03:19:07 +00:00
C. Scott Ananian
0a53c9725a Refactor magic word implementations out of Parser.php
This allows them to be more easily reused by other Parser implementations
(ie, Parsoid), and helps keep Parser.php compact.

Bug: T236813
Change-Id: I68fb1e786374e445b7df047934c532d7e10b8e94
2020-04-10 14:43:40 -04:00
Tim Starling
3c59969f9e Revert "maintenance: Remove sql.php temporarily"
I confirmed that the LoadExtensionSchemaUpdates hook no longer runs
after the parent patch to fix T249584 is merged, in either sql.php or
patchSql.php.

Note that sql.php is not just a "debugging script", it's intended for
use in production, and was used in production, hence T249565.

Bug: T249565
Bug: T157651
Change-Id: Ia4d99e00e6455eec9cf0fa486ec5e4b83c9cf25d
2020-04-09 00:46:49 +00:00
Timo Tijhof
b5f95da54b maintenance: Remove sql.php temporarily
It's dangerously broken.

This is supposed to be a read-only ad-hoc debugging script but in actually
triggers 'LoadExtensionSchemaUpdates', which is effectively update.php, but
without any of the safe guards, and at a time where you least expect write
queries to happen, let alone administrative queries that drop tables and
run other schema migrations.

Bug: T157651
Change-Id: I8d18a7f5b1731333aa40a9d04dafdb7176cf1d52
2020-04-07 00:04:37 +00:00
Sam Wilson
83804ade46 Purge expired watchlist items
Add two methods to remove expired watchlist items:
1. A job that's triggered on about 10% of page edits; and
2. A new maintenance script.

Bug: T244804
Change-Id: Ica8ab92837c38fa4d484726c94d5181c08387e28
2020-03-26 07:54:20 +08:00
Aaron Schulz
97fa6ff265 Move Xml* classes under /xml
Change-Id: I012648c9a860611a7cd809119073803e82429fc3
2020-03-19 19:23:47 -07:00
jenkins-bot
303d97c5da Merge "resourceloader: Merge 'user.tokens' module into 'user.options'" 2020-03-18 04:07:21 +00: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
Peter Ovchyn
176531d8c7 Introduce Emailer as service
In order to test functionality dependant on sending emails
Emailer should be introduced as service

Bug: T247229
Change-Id: I4fcceb7860a9a4dda091fb4cffcd2f6950fffaf8
2020-03-17 21:41:34 +02:00
Roan Kattouw
ca46126e98 resourceloader: Support single-file component .vue files
Allows .vue files to be used in package modules as if they were .js
files: they can be added to the 'packageFiles' array in module
definitions, and require()d from JS files.

In the load.php output, each .vue file is transformed to a function that
contains the JS from the <script> tag, then a line that sets
module.exports.template to the contents of the <template> tag (encoded
as a string). The contents of the <style> tag are added to the module's
styles.

Internally, the type of a .vue file is inferred as 'script-vue', and the
file is parsed with VueComponentParser, which extracts the three parts.
After the transformation, the file's type is set to 'script+style', and
files of this type contribute to both getScript() and getStyles().

This change also adds caching to getPackageFiles(), because it now needs
to be called twice (in getScript() and getStyles()).

Change-Id: Ic0a5c771901450a518eb7d24456053956507e1ed
2020-03-12 14:32:41 -07:00
jenkins-bot
2296134f52 Merge "Add PSR-4 mappings for existing namespaces and the top level" 2020-03-12 17:44:05 +00:00
jenkins-bot
43705de4f9 Merge "Add RefreshSecondaryDataUpdate and use it in DerivedPageDataUpdater" 2020-03-12 17:43:57 +00:00
jenkins-bot
e005e08768 Merge "Add a ContentModelChange helper, and an api module that uses it" 2020-03-11 22:10:01 +00:00
Aaron Schulz
1f4efc6c34 Add RefreshSecondaryDataUpdate and use it in DerivedPageDataUpdater
This class implements EnqueueableDataUpdate and can be pushed as a
job if it fails to run via DeferredUpdates.

Unlike a1f7fd3ada, make RefreshSecondaryDataUpdate skip failing
updates in doUpdate(). Instead of throwing the first exception from
any update, log any exceptions that occur and try all the other
updates. The first error will be re-thrown afterwards.

Also, make sure that each DataUpdate still has outer transaction
scope. This property is documented at mediawiki.org and should not
be changed.

Add integration tests for RefreshSecondaryDataUpdateTest.

Bug: T218456
Bug: T206283
Change-Id: I7c6554a4d4cd76dfe7cd2967afe30b3aa1069fcb
2020-03-11 00:42:48 -07:00
Tim Starling
f81462048a Add PSR-4 mappings for existing namespaces and the top level
This reduces the size of the class map ($wgAutoloadLocalClasses),
and allows new classes and namespaces to be added without modifying
the class or namespace map as long as they conform to PSR-4.

Adding a PSR-4 mapping for the top-level MediaWiki namespace means that
conforming subnamespaces do not need to be listed.

I did not add some odd or broken cases, since I figure it's better to
fix them by moving the files, which can be done in a separate commit.

I removed testPSR4Completeness, since PSR-4 completeness is no longer
required, that's the point.

Bug: T166010
Change-Id: Ie5e50ecb519b99a1197688c046c7be245ce6da1b
2020-03-10 21:08:30 +11:00
jenkins-bot
19e1d9a08d Merge "objectcache: split out StorageAwareness/ExpirationAwareness from IExpiringStore" 2020-03-03 22:55:24 +00:00
jenkins-bot
25a0d01d19 Merge "Revert "Split FakeMaintenance and LoggedUpdateMaintenance to their own files"" 2020-03-03 14:30:58 +00:00
Daimona Eaytoy
7def03fe80 Revert "Split FakeMaintenance and LoggedUpdateMaintenance to their own files"
This reverts commit 2cdeb26d0c.

Reason for revert: broke roughly all scripts extending LoggedUpdateMaintenance.

Bug: T246754
Change-Id: Icfe3da924c364b4b4f9286871aeb0aa9f1bbff1a
2020-03-03 14:14:31 +00:00
Aaron Schulz
69950da666 objectcache: split out StorageAwareness/ExpirationAwareness from IExpiringStore
Add more detailed QOS_* constants while at it

Bug: T236412
Change-Id: Ia862c5111a3daf10a34fc78163301629228efa6b
2020-03-02 20:01:24 +00:00
Reedy
c448337b61 Add a maintenance script to block a list of users
Bug: T246368
Change-Id: I93b7d92023af06adabd7767f30b5179d12223be1
2020-03-02 19:35:03 +00:00
Reedy
2cdeb26d0c Split FakeMaintenance and LoggedUpdateMaintenance to their own files
Change-Id: I4c95f910993fffa060c2860847b8cfff1612ccf5
2020-02-28 21:51:24 +00:00
DannyS712
0789d1568d Add a ContentModelChange helper, and an api module that uses it
Bug: T107174
Change-Id: I6eb38c4aec23619d7ec42ef12092edf9ff25c6fa
2020-02-27 19:02:29 +00:00
Timo Tijhof
007a0620db resourceloader: Convert mediawiki.Uri to package files
This replaces the client-side compiler for 'mediawiki.template.regexp',
with a simple PHP callback.

The regexp temple compiler is not used anywhere after this and will be
removed in a follow-up commit.

Bug: T233676
Change-Id: I1baa1465d88293d03975cadf2efdd57283427722
2020-02-24 17:45:31 +00:00
Tim Starling
44d51cb04e Fix the namespace of SpecialPageFactory
Follows-up d4045035b0.

This class was added to the MediaWiki\Special namespace, contrary to the
plan in T166010 which reserves that namespace for core special pages.
Instead, use MediaWiki\SpecialPage, following the directory in which it
is located.

Also, fix two bugs which prevented the introduction of a namespaced
class alias.

Bug: T166010
Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
2020-02-21 13:46:19 +11:00
Aaron Schulz
6b12696452 Move UIDGenerator code to a service and put it under /libs
All MediaWiki dependencies have been removed or injected.

Change-Id: I01c9e96edd6b03496c1595670967ffa5a4069c9d
2020-02-18 00:20:40 +00:00
jenkins-bot
b21453f61d Merge "widgets: Split out SearchWidgets into their own tree" 2020-02-15 00:20:08 +00:00