Commit graph

336 commits

Author SHA1 Message Date
jenkins-bot 50f293019c Merge "Rewrite MWTransclusionNode.isSingleTemplate for readability" 2021-07-01 11:21:44 +00:00
jenkins-bot 3709dfbee2 Merge "Update documentation for all getWikitext()/serialize() methods" 2021-07-01 11:18:08 +00:00
Thiemo Kreuz 4b62bc5bf1 Rewrite MWTransclusionNode.isSingleTemplate for readability
* Introduce variable names that explain better what's going on.
* Add comments.

Bug: T284895
Change-Id: Id5e8be9e52342ce049bdceec71f0f7cd01a6e2e9
2021-06-25 16:51:53 +02:00
Thiemo Kreuz 4367235dcc Inline many var declarations in the code below
This makes the code more readable and easier to reason about.
The ESLint rule responsible for this code style was removed
just recently.

Notes:
* I focus on classes that are relevant for what the WMDE team
  does right now.
* I merge multiple `var` keywords only when the variables are
  strongly connected.
* Caching the length in a for loop makes the code hard to
  read, but not really faster when it's a trivial property
  access anyway.

Bug: T284895
Change-Id: I621fed61d894a83dc95f58129bbe679d82b0f5f5
2021-06-23 09:02:24 +00:00
Thiemo Kreuz 58ec3006ba Update documentation for all getWikitext()/serialize() methods
There are at least 3 different methods that are all named
getWikitext, not counting subclasses. They behave rather
different, most notably in terms of whitespace preservation.

Bug: T284895
Change-Id: I8b47f5bd21675a431ba2bc2d4a8cb0c55dd50f76
2021-06-18 17:30:29 +02:00
jenkins-bot f6f3dfa54e Merge "Make use of Array.some() in a few places" 2021-06-17 08:52:54 +00:00
Thiemo Kreuz c2017f74b2 Remove @param/@return docs that literally repeat the code
These don't add any knowledge but make the code harder to read
and maintain, and are an additional source of errors.

Change-Id: Ied57741a3f985e355adfddb4e75378d5c497faa9
2021-06-14 15:44:51 +02:00
Thiemo Kreuz 858f0d51c0 Make use of Array.some() in a few places
some() is IE9+, so fine to use with our current compatibily
matrix.

Change-Id: I8d4a1b5326417bb4d23b47d72e5548f5def5784e
2021-06-09 07:34:50 +00:00
Bartosz Dziewoński 90e76e7c52 ve.dm.MWLanguageVariantNode: Fix "undefined" appearing for some nodes
The variable `html` had the value of undefined and was treated as a string.
This would then be displayed on the editing surface.

Change-Id: I4682ea121aa37f06cac41dde618af847586ae01e
2021-06-07 21:34:55 +02:00
jenkins-bot 8e5af5aafd Merge "Fix Parsoid HTML of broken images" 2021-02-26 19:54:52 +00:00
jenkins-bot cb21c4a158 Merge "Parse relative hrefs on image nodes like on regular links (try 2)" 2021-02-24 17:19:44 +00:00
Bartosz Dziewoński fd3ea87352 Fix Parsoid HTML of broken images
Parsoid doesn't like it when we send it an <img> tag for a missing image.

Bug: T266588
Change-Id: Ie42d667301b22942ac5bddd4c11db17c60a0fb5e
2021-02-04 20:39:05 +01:00
Bartosz Dziewoński 91291d3e98 Parse relative hrefs on image nodes like on regular links (try 2)
Previous, reverted attempt: da9b6fffbd.
This attempt also includes 6037fefbe0,
and fixes minor conflicts with other changes.

* In normal images, parse relative 'href' attributes instead of
  expanding them to absolute. This resolves Parsoid generating
  |link= options for copy-pasted images (T193253).

  Keep them in the underscore-form to avoid causing dirty diffs like
  T237040 again. Unlike in the previous attempt, we don't need to be
  super-careful about the 'resource' attribute, thanks to the Parsoid
  changes in T108504.

* In gallery images stuff, prefix the 'resource' attribute with './',
  same as normal images do. This causes no functional changes, but it
  makes updating tests easier, and the consistency is probably good.

* Update test examples to also prefix 'resource' and relative 'href'
  attributes with './', like the real Parsoid does.

Bug: T193253
Change-Id: I91131728a87c9406bf069d46d3c94c9a8905a003
2021-01-27 11:53:15 +00:00
Bartosz Dziewoński 0e9dd1751d Adjust CE markup of broken images so that Parsoid styles apply to them
Depends-On: I11fc7fc955656eee2a78461b509c3fee555e8613
Change-Id: Ieb958b372212423427ac0a36cd5ec374c927d232
2021-01-27 10:12:52 +01:00
Arlo Breault 895274c20b Switch back to using <span> for gallery images
Similar to I74fe96a47d8a4d7717891c16e49f5a4d6599018a

Bug: T266143
Change-Id: I632cff28ec428828d82fcd7cc66e5545c45c2161
2020-12-15 15:43:48 -05:00
Arlo Breault e3daaaf280 Preserve the passed in inline media tag name in gallery
Similar to Ic79aba4d4364227c3ecf7fb5411e90532b531f44

This only works if the gallery goes unedited.  Probably something needs
to be done in ve.ce.MWGalleryImageNode if we care to be complete.

However, as noted in T214648, the DOM diff'er doesn't traverse into
gallery content and notice these element names.  So, it's purely
academic to be doing this anyways.

Bug: T266143
Change-Id: I37799076852fa6f062c9d85bcebb15998fb44a80
2020-12-15 14:42:00 -05:00
Ed Sanders 5e170b63ca Switch back to using <span> for inline images
Bug: T266143
Change-Id: I74fe96a47d8a4d7717891c16e49f5a4d6599018a
2020-12-13 18:02:06 +00:00
Ed Sanders eafa3d2861 MWInlineImageNode: Rename figureInline to container
Change-Id: Ieda967dbd26532f44f71b4388e2357e780a381ce
2020-12-11 16:09:42 +00:00
Arlo Breault 6acddba351 Preserve the passed in inline media tag name
Bug: T266143
Change-Id: Ic79aba4d4364227c3ecf7fb5411e90532b531f44
2020-12-10 18:19:35 -05:00
Bartosz Dziewoński 80691d9404 ve.dm.MWInlineImageNode: Alienate malformed figures
Parsoid sometimes emits empty <figure-inline> tags. We can't edit
that, so alienate them, instead of throwing exceptions.

Bug: T267282
Change-Id: Ie6a659a9137a1c5e82f10e0a51abb5d60f68d43e
2020-11-05 22:47:35 +01:00
Arlo Breault d02c0bbf45 Allow alien extension node encapsulation wrappers to be of various types
Like transclusions, extensions can contain nodes of other types.  This
hasn't been an issue because the legacy parser doesn't generate content
with these annotations.  But, moving forward, as Parsoid becoming
responsible for more extensions.  This is the case for the new ImageMap
implementation.

Matches I95767e466803f0744b6626204a0a3a1514fff174

Change-Id: I6ff81a01207e2734090c626b177e5f4d10bb6d61
2020-10-20 11:44:54 -04:00
Ed Sanders 4545f53245 build: Update eslint-config-wikimedia to 0.17.0
Fix instances of variable shadowing.

Change-Id: I6e2befb020d7d4b506c7b46131eafacd951aa6d1
2020-08-18 13:16:49 +01:00
C. Scott Ananian ed3579245e French spacing (mw:DisplaySpace) doesn't have mw:Placeholder any more
The mw:Placeholder attribute semantically means, "don't touch this,"
but french spacing should be freely editable.  It's just a funny way
to write a plain wikitext space.

Bug: T254502
Depends-On: Ia164dd1318d45924aa965919e7939c6f817f5d0d
Change-Id: I56e0f0c6526649ea041e023698a48936176dec4b
2020-07-15 20:14:30 +00:00
Ed Sanders 5a017602c6 MWSignatureNode: Use template's rendering hash object
Bug: T256969
Change-Id: Ie573c677d1bf7f4e0306bcfcb0052e2b64025e89
2020-07-08 22:18:35 +02:00
Ed Sanders a8753df147 MWSignatureNode: Don't inherit from TransclusionNode
We don't share much functionality, and we have to do a bunch
of hacks to disable functionality we don't want.

Change-Id: I9861123d8f1cbab1923f1aa5be713c2dadaed53d
2020-07-08 22:18:35 +02:00
Ed Sanders 310b4d6e4c ve.dm.Node: blacklistedAnnotationTypes -> disallowedAnnotationTypes
Pulls through I69bea8829091b72f52e8486f7171d70e3194c6ef

Bug: T254646
Change-Id: Ibe880de0436e58416a857756d45fa4dc194196b1
2020-06-12 11:11:34 +01:00
Bartosz Dziewoński 89b6a8d71c ve.dm.MWIncludesNode: Change label for includeonly nodes per feedback
<includeonly /> is not valid wikitext markup, which is distracting.
Let's use <includeonly>…</includeonly> instead.

Bug: T250937
Change-Id: I9eac8b265eca16118d390da2628e0da7ca409ed8
2020-06-09 21:37:10 +02:00
jenkins-bot be3ad7d93a Merge "Handle <noinclude> etc. as nodes rather than metaitems" 2020-06-03 13:23:03 +00:00
Ed Sanders 6076708ff3 build: Update eslint-config-wikimedia to 0.16.0
Change-Id: I638e0f82949597e2a2e4ea18fc2f0258f225358c
2020-06-02 21:30:00 +01:00
Bartosz Dziewoński 1fc11e0146 Handle <noinclude> etc. as nodes rather than metaitems
The difference is that metaitems are not visible on the editing
surface, and their exact position is not preserved when the paragraph
containing them is edited.

This behavior is desirable for e.g. categories, but not for
<noinclude> and related tags, which are intentionally placed in
specific places in the text.

Note that we don't really have any editing interface for these nodes
yet. But you can see them (and they come with descriptions and links
to documentation pages), and delete or copy-paste them.

Bug: T250937
Change-Id: I104e7abbd650567df0e59813653c46a66d955d58
2020-06-01 18:47:14 +02:00
Ed Sanders 651756c4fc eslint: Enable the mediawiki/class-doc rule and make pass
Also minor other adjustments

Change-Id: I9ee48359e3e53799f2f6240e44b53972283ce328
2020-04-17 22:59:11 +01:00
Ed Sanders de47496b19 Move MWutils to preinit and rename to parsoid utils
Bring in ve.dm.MWInternalLinkAnnotation.static.getTargetDataFromHref
and ve.resolveUrl, so that the file has no dependencies on VE.

Change-Id: I03bc455d5484a6c51f3fa2397c64936b829fe7e3
2020-03-24 23:13:16 +01:00
jenkins-bot 95a20dbc08 Merge "ve.dm.MWGalleryNode: Preserve 'class' attribute unchanged" 2020-02-15 16:59:56 +00:00
Bartosz Dziewoński 26062fd3a0 ve.dm.MWGalleryNode: Preserve 'class' attribute unchanged
By removing this line, we fall back to the default behavior,
which is to copy the attribute from the original DOM element.

The gallery is supposed to have a class indicating the type (packed,
traditional, etc.). However, Parsoid doesn't care about that and
instead reads the type from 'data-mw'. Instead, changing the attribute
is causing dirty diffs.

Bug: T214649
Change-Id: I96b5a21777046b1caf07a3b1def9fad81bb15939
2020-02-14 22:05:50 +01:00
Bartosz Dziewoński 9119e57a2e Improve rendering of audio files (for real this time)
ve.dm.MWImageNode:
* Define sensible scalable properties for audio files. They are now
  scalable to any width but have a fixed height. (Ideally they would
  have no concept of height, but that would require many more changes.)
  This prevents them from resetting to 0x0 when resized.

ve.ce.MWBlockImageNode:
* Remove override for #isResizable, audio files can be resized now.
* Move #updateMediaType to MWImageNode mixin so it applies to
  MWInlineImageNode as well.

ve.ce.MWImageNode:
* Add #updateMediaType from MWBlockImageNode.
* Hide the real image 'src' using CSS rather than changing the
  attribute. It seems the previous solution depended on the order in
  which methods are called, because it stopped working when I moved
  the code here. (This depends on VE/VE change If5b1b5b5d.)

audioPlayer.svg:
* Make the file nicely resizeable. The dimensions of the "play" icon
  and time are fixed, the bar adjusts to the width of the container.

Bug: T206022
Change-Id: Ia0f38ca11e0d55a5b725fd9aeb6c79ec1345376d
2020-02-14 04:18:28 +01:00
Esanders c9b2e8b4d2 Only preserve data-parsoid/RESTBase ID on transclusion nodes
The previous attempt to fix this didn't preserve any attributes
but removing data-parsoid can result in a loss of wikitext formatting.

This reverts commit bdfd4b6d8f.

Bug: T207325
Change-Id: I2a38e651d17262889eddb149c72c9e08b4e56ed0
2020-02-12 22:51:43 +00:00
jenkins-bot 582b99781c Merge "Change gallery structure to match Parsoid" 2020-02-05 00:52:51 +00:00
Bartosz Dziewoński 353549003a Change gallery structure to match Parsoid
Bug: T214649
Change-Id: Ia5eb2057a8073488de2228315f08a20656ee946b
2020-02-04 20:02:18 +00:00
jenkins-bot bc2204b6c0 Merge "Add handling for mw:DisplaySpace" 2020-01-08 22:26:08 +00:00
James D. Forrester 2c77e88d2c doc: Bump copyright year for 2020
Change-Id: I30539877543dc2a57bd1428a00d10ac46d8fc294
2020-01-08 09:13:24 -08:00
Bartosz Dziewoński 8341f96217 Add handling for mw:DisplaySpace
It's supposed to be non-editable but deletable text, like mw:Entity.
We decided to handle them this way in 2015 but never implemented it
(T94509). Currently, accidentally editing text inside of
mw:DisplaySpace node causes the changes to be lost when saving.

Bug: T241906
Change-Id: I78a0cc7a75061a7eefb8b677898b5756326615d6
2020-01-08 01:40:12 +01:00
Ed Sanders cc217cef29 Avoid use of $.parseHTML in model
Change-Id: Ide671e7459b14bfbb7385261221c2edd17bd1153
2019-11-04 13:23:12 +00:00
Ed Sanders 2d4234fac8 Remove jQuery from ve.dm.MWLanguageVariantNode
Change-Id: I849cb6756171aa7bba43dc390cbd390b323328d2
2019-11-02 16:28:32 +00:00
David Chan 22098d6b16 Convert $.Deferred() to ve.createDeferred(), except in preinit
Follow-up to a8e07e026dea4f54241d1dbb6b7bcdbd8c670db2 in core.

Change-Id: I09333adb4876c6e584a4a6b6a1628227c4cd2616
2019-11-02 13:06:28 +08:00
Bartosz Dziewoński 00eb79d4d7 Revert "Parse relative hrefs on image nodes like on regular links"
This reverts commit 6037fefbe0.
This reverts commit da9b6fffbd.

Bug: T237040
Change-Id: Id6ea5784512e4d4c3cb00927b859d713c3814f89
2019-10-31 22:40:42 +01:00
Bartosz Dziewoński 6037fefbe0 Fix media embeds which don't link to the file page
Follow-up to da9b6fffbd.

Bug: T235707
Change-Id: Ie5a12bf274ae6178106f81a4c84686a88307c9fb
2019-10-17 22:12:58 +02:00
Bartosz Dziewoński da9b6fffbd Parse relative hrefs on image nodes like on regular links
* In normal images, parse relative 'href' attributes instead of
  expanding them to absolute, and parse 'resource' to keep it
  identical to 'href' if they refer to the same page (including
  same percent-encoding and space/underscore). This resolves Parsoid
  generating |link= options for copy-pasted images (T193253).

* In gallery images stuff, prefix the 'resource' attribute with './',
  same as normal images do. This causes no functional changes, but it
  makes updating tests easier, and the consistency is probably good.

* Update test examples to also prefix 'resource' and relative 'href'
  attributes with './', like the real Parsoid does.

Bug: T193253
Change-Id: If2d7f080d9d693568054f8311c1e1b15ca27ea5c
2019-09-25 00:25:04 +02:00
Ed Sanders 4a8947686d Docs: Standardise "messages used" comments
Change-Id: Ic563901a9439e86ca85ac6210323a35ab34736c3
2019-08-28 16:41:19 +01:00
Bartosz Dziewoński 84d548e7b1 Remove redundant @method annotations
A @method annotation is only necessary when the docblock is not
directly followed by a function declaration (in which case JSDuck
assumes it documents a property), e.g. when defining an abstract
function or referencing a function from another library.

I verified that JSDuck generates exactly the same output before and
after this change (docs/data-<hash>.js files are identical).

Change-Id: I7edf51a8560ab9978b42800ab1026f0b5555c3bf
2019-08-21 23:33:15 +02:00
Bartosz Dziewoński 3ca8319dfc ve.dm.MWTransclusionNode: Protect <style> nodes too when copying
Bug: T226374
Change-Id: Ie7853382642336638e0a1de9ca506d750ce054ce
2019-07-16 22:51:28 +02:00