2010-10-19 18:25:42 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2015-10-28 03:24:40 +00:00
|
|
|
* ResourceLoader module for user preference customizations.
|
2012-04-30 07:16:10 +00:00
|
|
|
*
|
2010-10-19 18:25:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @author Trevor Parscal
|
|
|
|
|
* @author Roan Kattouw
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Module for user preference customizations
|
|
|
|
|
*/
|
|
|
|
|
class ResourceLoaderUserOptionsModule extends ResourceLoaderModule {
|
|
|
|
|
|
2011-02-04 16:39:17 +00:00
|
|
|
protected $origin = self::ORIGIN_CORE_INDIVIDUAL;
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
protected $targets = [ 'desktop', 'mobile' ];
|
2013-10-15 22:31:14 +00:00
|
|
|
|
2014-12-04 07:37:56 +00:00
|
|
|
/**
|
2015-04-08 21:34:08 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2014-12-04 07:37:56 +00:00
|
|
|
* @return array List of module names as strings
|
|
|
|
|
*/
|
2015-04-08 21:34:08 +00:00
|
|
|
public function getDependencies( ResourceLoaderContext $context = null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [ 'user.defaults' ];
|
2014-12-04 07:37:56 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
resourceloader: Enable module content version for data modules
This greatly simplifies logic required to compute module versions.
It also makes it significantly less error-prone.
Since f37cee996e, we support hashes as versions (instead of timestamps).
This means we can build a hash of the content directly, instead of compiling a
large array with all values that may influence the module content somehow.
Benefits:
* Remove all methods and logic related to querying database and disk for
timestamps, revision numbers, definition summaries, cache epochs, and more.
* No longer needlessly invalidate cache as a result of no-op changes to
implementation datails. Due to inclusion of absolute file paths in the
definition summary, cache was always invalidated when moving wikis to newer
MediaWiki branches; even if the module observed no actual changes.
* When changes are reverted within a certain period of time, old caches can now
be re-used. The module would produce the same version hash as before.
Previously when a change was deployed and then reverted, all web clients (even
those that never saw the bad version) would have re-fetch modules because the
version increased.
Updated unit tests to account for the change in version. New default version of
empty test modules is: "mvgTPvXh". For the record, this comes from the base64
encoding of the SHA1 digest of the JSON serialised form of the module content:
> $str = '{"scripts":"","styles":{"css":[]},"messagesBlob":"{}"}';
> echo base64_encode(sha1($str, true));
> FEb3+VuiUm/fOMfod1bjw/te+AQ=
Enabled content versioning for the data modules in MediaWiki core:
* EditToolbarModule
* JqueryMsgModule
* LanguageDataModule
* LanguageNamesModule
* SpecialCharacterDataModule
* UserCSSPrefsModule
* UserDefaultsModule
* UserOptionsModule
The FileModule and base class explicitly disable it for now and keep their
current behaviour of using the definition summary. We may remove it later, but
that requires more performance testing first.
Explicitly disable it in the WikiModule class to avoid breakage when the
default changes.
Ref T98087.
Change-Id: I782df43c50dfcfb7d7592f744e13a3a0430b0dc6
2015-06-02 17:27:23 +00:00
|
|
|
* @return bool
|
2011-05-21 17:45:20 +00:00
|
|
|
*/
|
resourceloader: Enable module content version for data modules
This greatly simplifies logic required to compute module versions.
It also makes it significantly less error-prone.
Since f37cee996e, we support hashes as versions (instead of timestamps).
This means we can build a hash of the content directly, instead of compiling a
large array with all values that may influence the module content somehow.
Benefits:
* Remove all methods and logic related to querying database and disk for
timestamps, revision numbers, definition summaries, cache epochs, and more.
* No longer needlessly invalidate cache as a result of no-op changes to
implementation datails. Due to inclusion of absolute file paths in the
definition summary, cache was always invalidated when moving wikis to newer
MediaWiki branches; even if the module observed no actual changes.
* When changes are reverted within a certain period of time, old caches can now
be re-used. The module would produce the same version hash as before.
Previously when a change was deployed and then reverted, all web clients (even
those that never saw the bad version) would have re-fetch modules because the
version increased.
Updated unit tests to account for the change in version. New default version of
empty test modules is: "mvgTPvXh". For the record, this comes from the base64
encoding of the SHA1 digest of the JSON serialised form of the module content:
> $str = '{"scripts":"","styles":{"css":[]},"messagesBlob":"{}"}';
> echo base64_encode(sha1($str, true));
> FEb3+VuiUm/fOMfod1bjw/te+AQ=
Enabled content versioning for the data modules in MediaWiki core:
* EditToolbarModule
* JqueryMsgModule
* LanguageDataModule
* LanguageNamesModule
* SpecialCharacterDataModule
* UserCSSPrefsModule
* UserDefaultsModule
* UserOptionsModule
The FileModule and base class explicitly disable it for now and keep their
current behaviour of using the definition summary. We may remove it later, but
that requires more performance testing first.
Explicitly disable it in the WikiModule class to avoid breakage when the
default changes.
Ref T98087.
Change-Id: I782df43c50dfcfb7d7592f744e13a3a0430b0dc6
2015-06-02 17:27:23 +00:00
|
|
|
public function enableModuleContentVersion() {
|
|
|
|
|
return true;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
2014-04-20 21:33:05 +00:00
|
|
|
* @param ResourceLoaderContext $context
|
2017-04-03 08:24:41 +00:00
|
|
|
* @return string JavaScript code
|
2011-05-21 17:45:20 +00:00
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getScript( ResourceLoaderContext $context ) {
|
2011-10-14 08:06:54 +00:00
|
|
|
return Xml::encodeJsCall( 'mw.user.options.set',
|
2016-02-17 09:09:32 +00:00
|
|
|
[ $context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS ) ],
|
2013-02-21 02:30:45 +00:00
|
|
|
ResourceLoader::inDebugMode()
|
resourceloader: Disable minify for embedded 'user.options' module
Follows-up 6fa489392815 (T84960), which disabled minification
for 'user.tokens'.
In 2014 'user.tokens' module was changed to change tokens on every page view,
even for the same user within a short period of time. This led to a huge
minify-cache growth, and we subsequently disabled caching for its minification
result.
Since then, we have also done:
* Disable minification for 'user.tokens' more generally, given
that it's just a simple JSON blob and we already pass down the 'debug' mode
flag down to the creation of that blob, so there's virtually nothing to left
to minify.
* Disable minification for mw.config.set(). Config values are exported by
ResourceLoaderClientHtml and not part of any module. Given that since 2015
we minify per-module and not per-response (b7eb243d92) that means config
data naturally doesn't go through minification, which is good, because
just like for 'user.tokens', the config data is JSON which is already created
without whitespace. Minification would be pointless.
However, 'user.options' is still being minified and cached, and makes up about
25% of the 'resourceloader:minify-js.*' keys in APC on Wikimedia servers.
Unlike 'user.tokens', the minify cache for 'user.options' does actually get
used by subsequent page views from the same user (unless preferences changed).
However, it isn't useful because it's plain JSON and already compressed enough.
Besides, the blob is so small that it's not worth the overhead of cache-checking.
If we would want to minify it, I'd recommend we re-minify each view without cache.
Change-Id: Ic0ffb0e23df9b40e2c1283c89bd876a5c0555951
2018-01-29 23:14:19 +00:00
|
|
|
) . ResourceLoader::FILTER_NOMIN;
|
2010-10-19 18:25:42 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-21 22:08:23 +00:00
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function supportsURLLoading() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 17:49:57 +00:00
|
|
|
/**
|
|
|
|
|
* @param ResourceLoaderContext $context
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isKnownEmpty( ResourceLoaderContext $context ) {
|
|
|
|
|
return !$context->getUserObj()->getOptions( User::GETOPTIONS_EXCLUDE_DEFAULTS );
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 17:45:20 +00:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2010-10-19 18:25:42 +00:00
|
|
|
public function getGroup() {
|
|
|
|
|
return 'private';
|
|
|
|
|
}
|
|
|
|
|
}
|