Commit graph

167 commits

Author SHA1 Message Date
Ed Sanders e91cd00a2f Make all annotations additive
Any annotation could have a style attribute which has
a compound effect, and this also prevents roundtrip
errors. Button tool logic should prevent any annotation
from being applied twice which shouldn't be.

Bug: 49755
Change-Id: I8502a55cd2b195d28d0e2ecd63f15de670f80d60
2013-07-05 21:01:20 +00:00
Roan Kattouw 92c38eab85 The great directory split of 2013
Move all MW-specific files into the ve-mw directory, in preparation
for moving them out into a separate repo.

All MW-specific files were moved into a parallel directory structure
in modules/ve-mw . Files with both generic and MW-specific things were
split up. Files in ve/init/mw/ were moved to ve-mw/init/ rather than
ve-mw/init/mw ; they're still named ve.init.mw.* but we should change
that. Some of the test files for core classes had MW-specific test cases,
so those were split up and the test runner was duplicated; we should
refactor our tests to use data providers so we can add cases more easily.

Split files:
* ve.ce.Node.css
* ve.ce.ContentBranchNode.test.js (MWEntityNode)
* ve.ce.Document.test.js (some core test cases genericized)
* ve.dm.InternalList.test.js (uses mwReference test document)
* ve.dm.SurfaceFragment.test.js, ve.ui.FormatAction.test.js
** Made core tests use heading instead of mwHeading
** Updated core tests because normal headings don't break out of lists
** Moved test runners into ve.test.utils.js
* ve.ui.Icons-*.css
* ve.ui.Dialog.css (MW parts into ve.ui.MWDialog.css)
* ve.ui.Tool.css
* ve.ui.Widget.css (move ve-ui-rtl and ve-ui-ltr to ve.ui.css)

ve.dm.Converter.test.js: Moved runner functions into ve.test.utils.js

ve.dm.example.js:
* Refactored createExampleDocument so mwExample can use it
* Removed wgExtensionAssetsPath detection, moved into mw-preload.js
* Genericized withMeta example document (original version copied to mwExample)
* Moved references example document to mwExample

ve.dm.mwExample.js:
* Move withMeta and references example documents from ve.dm.example.js
* Add createExampleDocument function

ve-mw/test/index.php: Runner for MW-specific tests only

ve-mw/test/mw-preload.js: Sets VE_TESTDIR for Special:JavaScriptTest only

ve.ui.Window.js:
* Remove magic path interpolation in addLocalStyleSheets()
* Pass full(er) paths to addLocalStyleSheets(), here and in subclasses

ve.ui.MWDialog.js: Subclass of Dialog that adds MW versions of stylesheets

ve.ui.MW*Dialog.js:
* Subclass MWDialog rather than Dialog
* Load both core and MW versions of stylesheets that have both

ve.ui.PagedDialog.js: Converted to a mixin rather than an abstract base class
* Don't inherit ve.ui.Dialog
* Rather than overriding initialize(), provide initializePages() which the
  host class is supposed to call from its initialize()
* Rename onOutlineSelect to onPageOutlineSelect

ve.ui.MWMetaDialog.js, ve.ui.MWTransclusionDialog.js:
* Use PagedDialog as a mixin rather than a base class, inherit MWDialog

bullet-icon.png: Unused, deleted

Stuff we should do later:
* Refactor tests to use data providers
* Write utility function for SVG compat check
* Separate omnibus CSS files such as ve.ui.Widget.css
* Separate omnibus RL modules
* Use icon classes in ViewPageTarget

Change-Id: I1b28f8ba7f2d2513e5c634927a854686fb9dd5a5
2013-07-02 20:51:38 -07:00
Ed Sanders 37cf529d73 Allow annotations to be additive
Set a static property on big, small, sup, sub to allow them
to be added multiple times to an annotationSet.

Fix the converter to count out annotations when opening/closing.

Bug: 49755
Change-Id: Ifbede9345a66434022dbd681eada447ab81ab025
2013-07-02 21:43:47 +01:00
jenkins-bot c75e379086 Merge "Fix bug where whitespace in an empty node was doubled" 2013-07-01 17:15:58 +00:00
jenkins-bot 74ec334a30 Merge "Fix reordering of metadata bug" 2013-07-01 17:09:30 +00:00
Roan Kattouw f93b051acf Fix bug where whitespace in an empty node was doubled
<table>\n\n</table> round-tripped to <table>\n\n\n\n</table> because
we would store '\n\n' in both the innerPre and innerPost fields.
Fixed by not setting innerPost if the element is empty.

Change-Id: I0393bfaf9793fdebc8fff72c8760113fa69bb2bd
2013-06-30 00:29:38 -07:00
Roan Kattouw 46c3d48ba7 Also annotate empty annotations
The converter wasn't setting .annotations on meta items created to
represent empty annotations, which meant that HTML like
<i>Foo<b></b></i> would end up as <i>Foo</i><b></b> in the linmod.

Change-Id: I13d7d9820beeee1e8c3673e08051361d6c6ac4cd
2013-06-29 23:51:34 -07:00
Roan Kattouw 414709c5cb Fix reordering of metadata bug
If you had <meta /><b>Annotated text</b> in a wrapper paragraph,
the converter would swap them and output the linear model equivalent
of <p wrapper><b>Annotated text</b></p><meta />.

This happened because the meta item was queued, and annotations didn't
trigger metadata queue flushes. The fix is to trigger a metadata queue
flush whenever we're about to write something that isn't itself queued.

Change-Id: I168abc0392fbec5503271d1653ee5c38518f857d
2013-06-29 22:35:21 -07:00
Ed Sanders d1aca4503e Separate out MW specific converter tests
They are only run in the MW test runner, where the MW dependencies
are available. Create a ve.test namespace for storing shared
test runners.

Change-Id: I079cb18b1c73614d25a12c5d6afcf0700469e52e
2013-06-27 17:10:25 +01:00
Roan Kattouw 92ffa0739d Fix reserialization of mw-data.body.html
This bug caused all references containing complex content (e.g. links
or templates) to be dirty-DOMed and reformatted by Parsoid.

ve.dm.MWReferenceNode.js:
* Parse the original body.html and check if it's semantically equal to
  the new value. If so, don't set it.

ve.dm.Converter.js:
* .normalize() the converter output to remove empty text nodes and
  merge adjacent text nodes

ve.dm.example.js:
* Update reused reference test to have body.html absent, not empty
* Add a link to one of the reference tests so this bug is triggered
** The link's attributes are ordered specifically so that toDomElements
   will reorder them, at least in Chrome (may behave differently in
   other browsers)
** This test fails without this fix in place

Change-Id: Idc091a14422fbb117a3d06fc6bb9497768086fc3
2013-06-25 19:24:18 -07:00
jenkins-bot 2b7e47b8ab Merge "Don't drop annotated comments in wrappers" 2013-06-25 22:54:42 +00:00
jenkins-bot 324e7558c9 Merge "Revert "ve.dm.Transaction: Implement newFromDocumentInsertion"" 2013-06-25 22:14:15 +00:00
Catrope 721f8e0443 Revert "ve.dm.Transaction: Implement newFromDocumentInsertion"
Broke reference insertion because it removed
newFromNodeReplacement(), which is still in use.

This reverts commit 1765e39b40

Change-Id: I043997715474ad4850329ff903eb7a8c61c8b453
2013-06-25 22:08:37 +00:00
Roan Kattouw f9e698db22 Don't drop annotated comments in wrappers
HTML like <td><span>Foo<!--bar--></span></td> would lose the comment
when converting to linmod, and so we'd drop the comment when converting
back to HTML.

This happened because we were queueing up meta items to possibly move
them and their whitespace out of the wrapper paragraph even if we were
inside of an annotation and there was no way we could move things out
at all. The fix is simply to detect these case and not queue up meta
items in that case.

[12:11]	marktraceur	Let the comments hit the floor, let the comments hit the floor
[12:11]	marktraceur	(to the tune of the Drowning Pool "Let the Bodies Hit the Floor")

Bug: 50071
Change-Id: I5a844e2e0655bc1db152b3805718324ca0bb04df
2013-06-25 12:38:17 -07:00
Roan Kattouw c48af4de1f Don't set rel="mw:thumb" on the <a> inside a block image
Causes DOM diffs

Change-Id: I54bd90cfcbdff4baa06f67cbeb2865dca357be19
2013-06-24 17:02:54 -07:00
jenkins-bot eea2f640d7 Merge "Preserve the class attribute for block images" 2013-06-24 23:51:51 +00:00
Roan Kattouw eafbac3412 Preserve the <a> inside of a reference <span>
This was a big gaping DOM diff that's been in there since the beginning,
but which we only found today.

Change-Id: Ie4e791b212ddd3210bc1d5c11308452bb57ae3ce
2013-06-24 16:20:45 -07:00
Roan Kattouw 5212505648 Preserve the class attribute for block images
Build the new set of classes as an array (avoiding the leading space),
and only set it if it differs from what was there before. This avoids
reordering the class attribute.

Change-Id: I863ec8de2e7637f76690c4e0b7db5e153fb7e408
2013-06-24 12:34:15 -07:00
jenkins-bot 281f91d581 Merge "Store original DOM elements of transclusions" 2013-06-24 16:02:32 +00:00
Ed Sanders 7cc8e495aa Store original DOM elements of transclusions
Prevents changing of DOM attributes on unmodified transclusions
as they can clash in the store.

Also use 'original' over 'orig' consistently.

Bug: 50079
Change-Id: Ib13bb206c49b1f5b186e40632a5c109def0f042e
2013-06-24 15:50:52 +00:00
jenkins-bot 1176f69887 Merge "ve.dm.Transaction: Implement newFromDocumentInsertion" 2013-06-24 14:22:08 +00:00
jenkins-bot cf062adbfc Merge "Pass full data (including meta) to converter in references" 2013-06-24 02:07:01 +00:00
jenkins-bot e8dabd8f37 Merge "Preserve data-mw verbatim if unchanged" 2013-06-24 02:05:44 +00:00
Ed Sanders b963747a45 Pass full data (including meta) to converter in references
Previously we were just passing a slice of the visible data, instead
of using getFullData.

Bug: 50059
Change-Id: I3bbea49132ef4a720a147ba9b170c39a0c00f711
2013-06-24 02:04:57 +00:00
Roan Kattouw 5a70aa5685 Preserve data-mw verbatim if unchanged
Previously we would reserialize the JSON blob in data-mw even if we
didn't change it, which potentially reordered keys and caused a DOM
diff.

Bug: 50066
Change-Id: If0a5bcc67d3a172de0e8839cfda11efacfbf36ff
2013-06-23 19:02:54 -07:00
Ed Sanders 4bcc07b120 Allow metadata to be annotated
To prevent dirty diffs when inline metadata appears inside annotations.

Bug: 50060
Change-Id: I40da3d5e8e987571195142304b1a853e177e36ff
2013-06-23 18:48:32 +01:00
Timo Tijhof 8a2c9431e6 Create ref list insertion tool
Fixes (follows-up I1b48ef5240, I6daff5c596):
* Invalid html passed to jQuery constructor.
* Use prop() instead of attr() for boolean values.
* Use append() instead of html() when appending nodes instead
  of parsing html.
* Rename shadowed variable name clash 'mw' to 'mwData'.
* Fix odd construction where we parse '{}' to create an empty
  object.
* Have ve.ce.MWReferenceListNode#update perform changes off-document
  in a detached tree.
* Fix deep property access that can fail. mwData is set to
  either JSON parse of data-mw attr or empty object.
  Accessing mwData.attrs.group needs to be guarded by whether
  mw.attrs is indeed set.
* Have `mw` and `about` attribtue in references list roundtrip
  (especially mw which can data we aren't editing/re-creating).
* Add missing 'refGroup' property to MWReferenceListNode's
  data element (similar to what MWReferenceNode already has).

Change-Id: I67e4f378ccd04e97361d8e58ae57db5353075756
2013-06-22 20:23:22 -07:00
Timo Tijhof fb007eb4f5 ve.dm.example: Use jQuery#toArray instead of jQuery#get
Better for performance (lower level, #get calls #toArray when
called without arguments) and more semantically correct.

Change-Id: I8e615674e51fd148367fd397bd169fa203a240ad
2013-06-21 18:03:59 -07:00
Ed Sanders bf621b3454 Change nested annotation test to test recursiveness
Change-Id: I16f39bd0f6e2b6719ff26f69a561145bb4ca0c2b
2013-06-21 19:47:10 +01:00
Ed Sanders 8bfbef1c5e Handle nested empty annotations
At the moment we create an alien meta item if an annotation
wraps contents of zero length, however we also need to handle
nested empty annotations, i.e. where the contents is other
empty annotations (i.e. alien meta items).

As alien meta items simply preserve DOM elements we don't
mind what type of alien meta items they are, so this also fixes
the case of an annotation wrapping another alien meta
e.g. a comment or <meta> tag.

Bug: 48605

Change-Id: I98d88b341efcd6384ee1fda5d6d7e1e1acb107aa
2013-06-21 17:20:06 +01:00
Catrope 1765e39b40 ve.dm.Transaction: Implement newFromDocumentInsertion
This function builds a transaction that takes a document slice and
inserts it back into the document it came from, applying any changes
that were made.

This makes editing document slices simple:
    slicedDoc = doc.getDocumentSlice( captionNode );
    // Edit slicedDoc using a surface
    tx = ve.dm.Transaction.newFromDocumentInsertion( doc, captionNode, slicedDoc );
    surface.change( tx );

Specifically, newFromDocumentInsertion replaces the node's contents
with the document's contents (meaning any changes made to the node in
the meantime are lost). It also merges the stores internal lists
of the two documents and remaps indexes accordingly. This means editing
of references inside of references is supported.

This functionality is not specific to slices, and can also be used to
safely insert data from a paste buffer, with internal list data being
transplanted correctly.

ve.dm.MetaLinearData:
* Make merge( [ undefined, undefined, ... ] ) return undefined rather
  than [].

ve.dm.Document:
* In getDocumentSlice, store a pointer to the original dm.Document in
  the new one, and also store the length of the internal list. This
  allows us to figure out which internal list items the two documents
  have in common when we insert the modified slice back into the main
  document.
* In getMetadataReplace, optionally take the inserted metadata as a
  parameter, to allow for operations that insert both data and metadata.
  Per Ed's review, rewrite this function to return null rather than {}
  if no metadata needs to be replaced.

ve.dm.InternalList:
* Add method to merge two internal lists

ve.dm.Transaction:
* Remove newFromNodeReplacement and replace it with newFromDocumentInsertion.
* In pushReplace, optionally take the inserted metadata as a parameter.

Change-Id: I786ee7bad796aa54bc242993b4de3ad18ad0773e
2013-06-19 17:27:50 -07:00
Ed Sanders 81bdb7cf3e Store originalIndex instead of mwOriginal in Transclusions
Slightly more efficient way of seeing if the template has changed,
and results in a cleaner set of data element attributes.

Change-Id: I1507520005bfb8a88bfa6038dac5c3b15506425d
2013-06-18 15:23:37 +01:00
Roan Kattouw 177159b388 Test case for 95733390dc
Change-Id: I8c2e239e945466f3e46c92efab03f7e615bc6887
2013-06-17 17:13:45 -07:00
Roan Kattouw d32abe903e Fix selectNodes() bug with empty non-content branch nodes
These kinds of empty nodes shouldn't occur since the converter fills
them with empty paragraphs, but selectNodes() should still behave
correctly for them.

Change-Id: Ia37f3db1c2a84b842e2311cf70642fa66af04d91
2013-06-17 19:09:12 +00:00
Roan Kattouw df97f759b1 Refactor selectNodes tests
* Move them from ve.example.js to ve.dm.example.js
** Also move lookupNode() and createDomElement() there
** Delete ve.example.js because there's nothing left in it
* Make main example document implicit, but allow override
* Specify nodes as arrays and do the lookup later
* Specify range and mode separately rather than calling selectNodes()
  during construction
* Construct statically rather than in a function
* Use expect( cases.length );

Change-Id: I620e949c5e612b32eaa57c5d9b60cc91f9ddbf02
2013-06-17 20:08:08 +01:00
jenkins-bot 4cad5463d4 Merge "Code style fix: @return -> @returns" 2013-06-17 17:53:54 +00:00
Roan Kattouw 393925a868 Build the internalList linmod even if it's empty
Otherwise fun exceptions occur when you have a <references /> tag
with no <ref>s, for instance.

Also disregard the internalList in the data->DOM conversion, to prevent
a nasty interaction where the whitespace information on the last element
is considered invalid because it doesn't match the internalList's.

Plus test updates from hell because this touches ve.dm.example.data

Change-Id: I62881d9fc27fa081123856d1b35a6021af469271
2013-06-17 13:23:20 +01:00
Ed Sanders dcbea2328c Code style fix: @return -> @returns
Change-Id: I26daca6313bf09055af8f980ba0065782257fd54
2013-06-17 11:50:24 +01:00
Roan Kattouw 0c16066eb3 Kill attribute order preservation
Per the bug report, it's useless because Firefox does not preserve order
in the .attributes array (but sorts it alphabetically instead), and so we
actually get the same exact behavior regardless of whether we use ordering
cleverness or just a straight-up plain object: order is preserved in Chrome,
and alphabetized in Firefox.

Bug: 48980
Change-Id: I1463d06db4900083dd4c565292bbabef09194b43
2013-06-13 23:17:08 -07:00
Trevor Parscal d3a2fab2c4 Transclusion editing
Objectives:

* Rename just about every use of "template" to "transclusion"
* Make a proper data structure for transclusions
* Abstract away template data
* Use more template data in the user interface
* Allow adding parameters
* Allow removing templates, parameters and content

Changes:

ve.ui.Dialog.css
* Add rule to place add param controls on a single line

ve.ui.MWTemplateDialogs.js
* Move template spec loading into transclusion class
* Add remove button for parts and parameters
* Add parameter adding form
* Use template data for labels and descriptions

ve.dm.*
* Add new transclusion data structures

*.php
* Add links to new files

*.*
* Rename all things "template" to "transclusion"

Bug: 39598
Bug: 49403
Change-Id: I3bcf924a3e179cb65f19e833277a39dfd3dad8bd
2013-06-12 16:39:13 -07:00
Ed Sanders da51566d56 Store empty annotations as alienMeta nodes
Not a perfect solution, but better than deleting them completely.

Bug: 48605
Change-Id: I0f3a194f629b054f193a61af105733a555775d79
2013-06-12 19:46:41 +01:00
Ed Sanders 59bfc081df Store alien meta items' dom nodes only
We don't need to decompose and rebuild alien meta items
as they are uneditable, so just store the dom node and return that
in toDomElements.

Update test cases and several tests now need to use
assert.deepEqualWithDomElements.

Change-Id: I4d2eed267dac7855cb929a17d7aef566eaf0e287
2013-06-12 16:37:37 +01:00
Trevor Parscal 8039b1c2f8 Insert Reference
Objective:

* Allow opening reference dialog with arbitrary selection
* Auto-insert reference when selection is not a reference node

Changes:

ve.init.mw.ViewPageTarget.js
* Added reference button to toolbar

ve.init.Target.js
* Add getToolbarSubset so we can exclude the reference button from
  the toolbar in the reference dialog (nested references are not
  allowed).

ve.ui.MWReferenceDialog.js
* Stop storing referenceNode (not needed)
* Only store internalItem on open if there's a focused node that's a
  reference
* Use wrapper paragraph when creating a new reference
* Create new reference on dialog close if required

ve.dm.InternalList.js
* Major rewrite to support key less references.
* Add new method for creating a transaction to insert a new iternal
  item. Also returns the index of the new item to be passed to the
  reference node.

Change-Id: I839ae165c299248484ce93d4ab087318a95fbb94
2013-06-10 20:14:08 +01:00
Ed Sanders 1a86cb9c61 Preserve location of reference body within key
Previously we populated the reference body into all <ref> tags
with the same key. Now we store an internal attribute marking
which element originally had the data.

If that tag is deleted the body is moved to the first <ref> tag
with that name.

Change-Id: If9f12bfb699e6ce85bb8f7d2ea9e6df528610a3d
2013-06-10 02:54:26 +00:00
jenkins-bot cd2f411a93 Merge "Support for inline images" 2013-06-07 23:13:19 +00:00
Inez Korczyński 2f15cb0067 Support for inline images
Handles typeof mw:Image and mw:Image/Frameless

Change-Id: Ie2fbd4a3e12fb6faa4ab8e6dd0aa8d1334ff6498
2013-06-07 23:09:32 +00:00
jenkins-bot 72f661dc69 Merge "ve.dm.MWBlockImageNode: Make toDomElements add more information to its output so round-tripping can work properly." 2013-06-06 21:46:21 +00:00
jenkins-bot 8c20fb278f Merge "'typeof' for templates changed in Parsoid, it is 'Transclusion' now and used to be 'Object/Template'" 2013-06-05 23:06:15 +00:00
Inez Korczyński 2f58dd3d40 'typeof' for templates changed in Parsoid, it is 'Transclusion' now and used to be 'Object/Template'
Change-Id: Ia5b826bc1a2a648a8e618642697484000b68bfc2
2013-06-05 15:31:51 -07:00
Ed Sanders 22d1908bd4 Update reference lists and inline numberings automatically.
The easy part is getting the correct numbers from the InternalList
and generating the ordered list HTML. The tricky part is connecting
up the events to make sure the renumberings/list generations are
triggered when required.

InternalList can emit an update event on document transaction, which
triggers the renumbering/relisting if any references have been
added or deleted during that transaction.

ve.ce.MWReferenceListNode also listens to changes on the
InternalListNode (i.e. changes to the contents of the references)
and always triggers a rebuild.

Change-Id: I1b48ef5240e433c3b314259aa68cde13841ea98b
2013-06-05 15:11:16 -07:00