Commit Graph

74 Commits

Author SHA1 Message Date
Timo Tijhof
fcfa36ac77 compactlinks: Optimise performance of list creation logic
Add potential items directly to a single array with two indexOf
checks.

Previously, potential items were first put in a new temporary array,
then that array was filtered with indexOf checks into another temporary
array, and then the result of that combined with the previous results
into another temporary filtered array, and then the previous results
array replaced with the new one. This eliminates 2*2N filter+concat
calls an their overhead from calling functions, creating arrays,
copying arrays and the memory for those arrays. (Where N is the number
of language-list strategies). It also reduces the total number of
indexOf calls.

Below is a comparison of time spent in createCompactList() during
page load process, compared to master without this and the previous
commit. Measured on localhost with Vector, EventLogging, Interwiki,
and ULS installed; on a page that is a copy of en.wikipedia.org/Messier_87
and its 51 interlanguage links. This page was a featured article
last week. Its count of links seems average compared to other
featured and/or most-viewed articles last week (the other ones
I checked had 23, 43, 52, and 76 langlinks respectively).

|--------------|----------|--------|
|              | Before   | After  |
|--------------|----------|--------|
| Chrome 69    | 77.5ms   | 41.4ms |
| MacBook Pro  | 57.7ms   | 44.4ms |
| CPU 1/6th    | 63.8ms   | 45.3ms |
|--------------|----------|--------|
| Firefox 61   | 12ms     | 10ms   |
|              | 10ms     | 9ms    |
|              | 11ms     | 8ms    |
|--------------|----------|--------|
| Safari 11    | 3.5ms    | 2.7ms  |
|              | 3.3ms    | 2.6ms  |
|              | 3.4ms    | 2.8ms  |
|--------------|----------|--------|

Bug: T127328
Change-Id: I56052e7c01c6a667500773e12c755a7a5f5d9cd0
2018-09-24 17:19:45 +00:00
Timo Tijhof
effcd80471 compactlinks: Optimise performance of DOM logic
The createCompactList() function runs synchronously during the
module execution burst. Due to it visually changing the page, I
won't defer it with rIC for the time being, although that should
be considered for the future. For this commit, I'm trying to make
it fit the budget of <50ms because ULS is currently usually taking
80ms-180ms on desktop (MacBook/Chrome CPU/4), and that's during
batch execution with other modules as well, thus freezing the
UI thread for much longer than that.

constructor:
* Remove needless clone of jQuery object.
  Use $foo instead of $( $foo ).
* Remove creation of 'interlanguageList' and 'compactList' objects
  that are immediately removed and re-created by init().

init/getInterlanguageList:
* Use the HTMLElement.lang and HTMLAnchorElement.href properties
  directly instead of the DOM getAttribute().
  This means stores a full url instead of a relative url, which
  should help avoid other bugs in the future.
* Remove needless jQuery() constructor and jQuery.text() call.
  Use Node.textContent directly instead.
* Use HTMLElement#querySelectorAll instead of jQuery#find().

init/getCompactList/../filterByLangsInText:
* Avoid jQuery() constructor and jQuery.attr(),
  use the HTMLElement.lang property directly.
* Avoid jQuery() selector, call querySelectorAll directly.

init/getCompactList/../getCommonLanguages/../getFrequentLanguageList:
* Avoid temporary array copies from concat() and function overhead
  with forEach() and filter().
  Instead, keep only a single array, and iterate it once.

init/getCompactList/../filterByBadges (~10m -> ~0.5ms):
* Use one query via $(), instead of two queries $()+find().
* Use $.map() directly instead of map()+fakejQueryObject+toArray().
* Use querySelector(One) for the child instead of $()+find().
* Use HTMLElement.lang property directly.

init/hideOriginal (~5m -> ~0.8ms):
* Use querySelectorAll() directly instead of jQuery find().
* Set HTMLElement.style directly instead of jQuery() css().

init/render/addTrigger:
* Use createElement() and direct properties instead of $(), addClass(),
  prop() and text().
* The mw.msg() calls use text() and jqueryMsg#parser which is
  expensive.
  Use plain() for 'ext-uls-compact-link-info', which doesn't need parsing.
  Keep text() for the other message, and document why.

init/listen:
* Use async Deferred#then() instead of sometimes-sync Deferred#done().

Bug: T127328
Change-Id: I424c34fb82c8e95407f7b934e6d42019becbf909
2018-09-13 11:11:42 +00:00
Fomafix
971e4c742d Simplify by using native JavaScript instead of jQuery
Still use $.each for iterating over an Object because there is no
adequate function in ES5.

Change-Id: Idbec13c471e75a9cd5d67204d54bededdbd5582b
2018-09-07 22:35:13 +00:00
Timo Tijhof
4e067715dc Remove redundant closure aliases
'mw' are '$' are globals, always have been, and aren't going
anywhere. They're every bit as real as their longer versions.
If anything, the longer ones are less "real" or 'stable" because
they're not used internally by RL and easier to accidentally
replace or override. For anecdotes and history, see 91f950d6b0.

Change-Id: I526fb8c961d9477992d88f2780a0ff4cbdc51923
2018-09-07 19:23:17 +00:00
Amire80
635cada69b Revert "Simplify by using native JavaScript instead of jQuery"
This reverts commit 0fbdbc2c41.

Bug: T203750
Change-Id: I1bca27b2087f6fc1bfad153f17f4650c52786a7f
2018-09-07 08:57:16 +00:00
Fomafix
0fbdbc2c41 Simplify by using native JavaScript instead of jQuery
Change-Id: I2ca5fbb21ac473f482579a944e5ab68c9374191c
2018-09-04 00:32:12 +00:00
Fomafix
72fb42cdba Remove support for MediaWiki 1.29 and earlier
extension.json already requires "MediaWiki": ">= 1.30.0".

Change-Id: Ic460e6364967cd7b0367e66f613077c424bd8f19
2018-08-31 21:41:42 +00:00
petarpetkovic
5a1da4dbaa Remove jQuery.inArray usages
Replace jQuery.inArray with JS native Array.prototype.indexOf

Change-Id: I0031f0385e440a34846334d158425182542a9ac9
2018-08-24 20:18:53 +00:00
petarpetkovic
54a3313e1a Remove jQuery.grep usages
Replace jQuery.grep with native JS Array.prototype.filter method.

Change-Id: Idbf88a516061ff46211f72e8b93e11f5fa838e88
2018-08-24 20:43:33 +02:00
petarpetkovic
9c0c918bab Replace jQuery.proxy() with Function.prototype.bind()
Also, one immediate invocation of jQuery.proxy() is replaced by
Function.prototype.call()

Change-Id: Ibbdbe6413793c113d4de1c67cfcb7d95676565b2
2018-06-18 06:56:09 +00:00
Fomafix
162cc56f02 Reorder functions to avoid forward references
Remove /* eslint-disable no-use-before-define */.

Change-Id: I001b50050d8c492aed99a3620b6fc03ffb29e135
2018-06-11 23:44:47 +00:00
Amire80
04a8eeb62c Switch the current tab to the new language only if it was not Ctrl/Command/Shift-Click
Bug: T189582
Change-Id: Ib497be874b3d559a8f1715d09160378f0c43881e
2018-03-26 15:40:56 +00:00
Amire80
d6630a4780 Log the context of the ULS in which no search results were found
Relies on updates to EventLogging schema. Diff:
https://meta.wikimedia.org/w/index.php?title=Schema%3AUniversalLanguageSelector&type=revision&diff=17799034&oldid=7327441

Bug: T179402
Change-Id: I2ff9ce9b40df16ed3c5e6970fb3b691af08cedec
2018-03-08 16:03:33 +02:00
Niklas Laxström
9a6e8a2bc9 Fix custom no results again
Since we added .i18n() call to upstream, it started overwriting
our text from the default data-i18n. Change data-i18n instead.

Bug: T188860
Change-Id: Ib7e9fb9590ace9c2a4ce2e2afb5a740ae4346be6
2018-03-05 14:17:12 +01:00
Kunal Mehta
67d470a9e7 Use SPDX 3.0 license identifier
SPDX released version 3 of their license list (<https://spdx.org/licenses/>),
which changed the FSF licenses to explicitly end in -only or -or-later
instead of relying on an easy to miss + symbol.

Bug: T183858
Change-Id: Id75a37eab27282ca7797fa3e6ceb92750c59477f
2018-03-03 19:27:21 +00:00
Santhosh Thottingal
28c455feaf Custom no-results message for compact links search
Bug: T182539
Change-Id: I0e3bb7104015a5244290058dc0ac5b3c17b1ea20
2018-02-08 10:38:06 +05:30
Amire80
cc1dd9fe8c Show the same tooltips on compact language links
The tooltips include the title of the target article
and the name of the language in the user's language.

Bug: T160976
Change-Id: If3dd416e4a6f13b7b1366d30a1a3807a505346cb
2017-10-11 10:01:47 +03:00
Isarra
86c636fd0a Fix directionality of ULS CLL and languageselect callouts
when appearing on right side of screen

Languageselect was mostly fixed in 354378, but I forgot the
settings ones, so the triangle just disappears when
switching dialogs currently. This follows up on that and
properly fixes it.

Sidebar callouts now appear toward content regardless of
where they're appearing from, or the language
directionality. Triangles are now consistently alligned to
the top of the callout (same position in languageselect and
compact language links) to avoid issues with it appearing
over a scrollbar.

Sideways callout triangles (carets) are consolidated into a
single rendering approach and mixin across compact language
links and toolbox language selector.

Bug: T161586
Change-Id: I7717e26525ac527ede486796f49083ed40ee7d4f
2017-08-10 23:48:34 -04:00
Amire80
757d28b114 Show languages from the Babel box on the user page
Bug: T135371
Change-Id: Ieeaf446326be93a779df3e6bd7a8dca899950a6c
2017-05-30 17:25:23 +03:00
Amire80
dcd53534f6 Comment spelling correction
Change-Id: I247644c71f981d7d57304468cab31b4e3057bb81
2017-03-11 16:24:35 +02:00
Fomafix
47cfd9c1ae Replace $( document ).ready(...) by $(...)
In jQuery 3 $(document).ready(...) is deprecated.
https://jquery.com/upgrade-guide/3.0/#deprecated-document-ready-handlers-other-than-jquery-function

Change-Id: I1a9f578d8cf8fa2d9dd38a1b2d3a0b3c32914b74
2017-01-06 14:10:55 +01:00
Ed Sanders
811944c49a build: Replace jscs+jshint with eslint
Change-Id: I7f114267fbb4efd62a9162758445cff4fb3c0973
2016-11-09 15:57:38 +00:00
Amire80
4bd38a0fcf Query only for <a> elements that are interlanguage links targets
Depends on the core change in 1.28, which adds the
interlanguage-link-target class to the <a> elements:
I06c80945af785477be52096022c8493e7f82c298

Includes backwards compatibility code so that ULS compact links
would be usable on core versions that don't have this change.

Bug: T135378
Change-Id: I2909ce31e19087358d194e0e108e1ba038e7273e
Depends-On: I06c80945af785477be52096022c8493e7f82c298
2016-11-01 12:59:35 +00:00
Amire80
908161f0c1 Add hooks fired when finished processing compact language links
Bug: T145755
Change-Id: I921191c2cd32d55161b32bad2b2e0d98228cf230
2016-09-27 13:34:02 +00:00
Niklas Laxström
2144019c50 ext.uls.compactlinks: consistently normalize language codes
Create a function for this purpose and use it everywhere where
language code is read from an attribute.

Bug: T143867
Change-Id: I01b6f04dd9185a9f4ab565e96ca5a6a34e4ea14a
2016-08-25 08:22:17 +00:00
Amire80
0d1d9a4b6d Apply toLowerCase when reading featured articles
Consistently with getInterlanguageList(). Without this 'nds-NL'
will be handled incorrectly when the article in it is featured.

Bug: T143527
Change-Id: Ie7fe5a270cb3030899b6034512351d5d66d7be06
2016-08-21 22:47:27 +03:00
eranroz
abaddfaccd Earlier evaluation of compactlinks
* Prospectively load ext.uls.init
* Prospectively check if readyState is interactive
Bug: T136463
Change-Id: Ib36ef6a2b9955189acfbe06bd6b498a66014cf06
2016-08-19 11:10:27 +00:00
Amire80
43f62e601c Add languages in which there is a featured article
Bug: T70071
Change-Id: I5ed2f1ece5b11b96ec6416bc1c6c2266ac6b4388
2016-08-04 19:42:46 +03:00
jenkins-bot
9c1decf616 Merge "CompactLinks: support sortPrepend from WikiBaseClient" 2016-08-02 05:14:55 +00:00
jenkins-bot
b8c79727d8 Merge "Show languages that appear in the page's text" 2016-08-01 06:31:24 +00:00
Santhosh Thottingal
df70f941b2 Show languages that appear in the page's text
This is just a simple search for elements with lang attribute.

This will be executed only when previous languages, geo-IP based languages,
browser, UI, content languages etc. are not filling the defined compact size.

Bug: T70077
Change-Id: I77d1efa5e29deeaaf595753fb5519c8b70c7f2b5
2016-07-28 17:32:10 +02:00
Niklas Laxström
89175716ec CompactLinks: lowercase language codes for internal use
Not outputting language codes with proper casing should
be solved upstream in jquery.uls.

Bug: T139795
Change-Id: Ide81c76135b23a031f1f09a33462e767e57a50b0
2016-07-27 05:57:03 +00:00
Niklas Laxström
4f4051a40d CompactLinks: support sortPrepend from WikiBaseClient
Bug: T138973
Change-Id: I64b7aa37d8a6b3cac92d492a33fe6f8cb04ce0e6
2016-07-26 13:36:26 +00:00
Santhosh Thottingal
26cfea8ef4 Compact language links: Use smaller callout arrow
Uses equilateral triangle with 16px side.

Bug: T138235
Change-Id: If81342876d59e3041d0ea4029e301c3cc76f6641
2016-07-12 12:17:33 +05:30
Santhosh Thottingal
d109bddf20 Compact links: Execute the compact strategies on need basis
We were executing all compacting strategies even when we have
more than enough items as candidates. If the strategy is expensive,
(performance wise) this is a problem.

In this commit, we execute them one by one and stop when we have enough
candidates.

The methods in CompactInterlanguageList class also arranged as
individual function declarations than comma seperated method list.

Change-Id: Idce6489387d139852125f4448d0e192f6a7e1353
2016-07-11 10:58:00 +02:00
Niklas Laxström
2a6b4d0fc2 Show badges in ULS language list
Update jquery.uls to ae9dda23b71aa76fbbc13f5650

Bug: T131233
Change-Id: I7c7bafccc7d63c0a97c98b81a5b53b48c9afa527
2016-06-09 15:12:39 +05:30
jenkins-bot
4b1056133f Merge "Make previous languages have most recent in the beginning" 2016-05-24 04:38:49 +00:00
Niklas Laxström
4f82a8650a Make previous languages have most recent in the beginning
This is already expected by the callers. Added addPreviousLanguage
to make updating the list easier.

Change-Id: Ie4f888235ea4de4a2ce6bf5a9f24955e423e8c48
2016-05-23 14:50:02 +02:00
jenkins-bot
43782e8635 Merge "Add some global fallbacks to compact language links" 2016-05-23 11:43:46 +00:00
jenkins-bot
384b109362 Merge "Update jquery.uls and adapt styling" 2016-05-23 11:09:01 +00:00
Niklas Laxström
021ceadc85 Add some global fallbacks to compact language links
Bug: T135366
Change-Id: I75cc58f79cb818d8330120d996d67c6b183c0843
2016-05-20 14:51:47 +02:00
Niklas Laxström
4ff7d5adf8 Add tooltip to the "more languages" action to provide better context
Bug: T135224
Change-Id: I3c5d909ff334182e25b48fd3917260087ee276ef
2016-05-19 08:56:04 +00:00
Niklas Laxström
a19e8c0dba Update jquery.uls and adapt styling
jquery.uls.compact module is kept for now as some other
extensions depend on it. But it does not do anything
anymore.

There are some styles which should be in jquery.uls
upstream, but given the current state that is easiest
done in a follow-up later.

The main change is that language selection is now
compact by default: no heading etc.

Includes style changes for the dialogs, and especially
for the new position of the callout caret.

Bug: T85519
Change-Id: Iade8005439b4f58ab241752f69a5365d8bb88d2c
2016-05-18 11:40:58 +02:00
Santhosh Thottingal
cbb46f7451 Compact language links: Delay loading of jquery.uls module
Load jquery.uls only when the trigger is clicked.
Reduces the initial footprint by 63.9 KB (uncompressed)

Bug: T135210
Change-Id: I972cb6ea1794485917ea530f7abe68bdddc2014f
2016-05-17 14:55:51 +05:30
Niklas Laxström
146949ce43 Fix fail in 1bc3f3b
Assignment got lost, so caching did not work.

Change-Id: If7f6df5b6c6d6156894803670263f34f2850a29a
2016-05-09 20:12:46 +02:00
Santhosh Thottingal
1bc3f3b065 Compact links: Avoid duplicate call of filterByCommonLanguages
It re-triggers mw.uls.getFrequentLanguageList(),
getPreviousLanguages() and localstorage read.

In this patch the result was saved and reused.

Bug: T122341
Change-Id: I14839eb611cd3e995e8d8ab729ee3f714840f9ad
2016-05-09 14:31:34 +05:30
Santhosh Thottingal
4150d24e67 Compact links: Simply use the widget pattern instead of plugin
We don't need plugin pattern here since it is not meant for a use
in multiple contexts. Code simplified.

Change-Id: Iee86069aaa82f5a9ab3a856c19360e9ea89211ad
2016-05-03 08:53:58 +05:30
Niklas Laxström
d2bb6e9010 Ensure ext.uls.mediawiki is loaded before use
Earlier patch loaded it too late, but it was loaded
anyway by something else.

Change-Id: Ib4cf6cd7339a5313961c84cd7904fc2ffc66a157
2016-04-22 10:56:48 +00:00
Niklas Laxström
c99a30bf80 Simplify code by using Object.keys
Guaranteed by es5-shim.

Change-Id: Ifd698dc03fd8e755e95ec6c4856ec3683cc3305d
2016-04-22 12:49:15 +02:00
Niklas Laxström
85f7ebdd4b Delay compact language links language selector creation until click
No point constructing the selector when it is used.

Task: T122341
Change-Id: I928f9041a95e2c48625dba6e11550ac6bbdcb7fd
2016-04-22 10:19:21 +00:00