YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Social Machines X Reaction

Get Embed Code
1 Language

Showing Revision 6 created 09/08/2014 by d.j.hartman.

  1. Engineering (VisualEditor)
    Against the Odds

  2. Alright
  3. Hello, everybody. I'm Trevor Pascal.
  4. This is Roan Kattouw and Ed Sanders,
    we work at the Wikimedia Foundation, specifically the VisualEditor
  5. and today we want to talk to you a little bit about
    some of the challenges that we have to deal with
  6. for the past couple of years
  7. and how working on VisualEditor is essentially engineering 'Against the odds'.
  8. And so in fact we have found that the odds are against us.
  9. But can anyone guess what makes creating VisualEditor so difficult ?
  10. Like what sort of things are standing in our way ?
  11. - The community
    The community.. definitely NOT !
  12. The green shirt ?
    - Ehm browser support ?
  13. Having to support like everything like IE6 and mobile ?
    - Oh [....] I don't think we ever claimed IE6 support...
  14. Anyone else ?
    - Working with wiki text
  15. Ah, yeah OK now we are getting good
    So yeah definitely differences in Operating Systems
  16. different kinds of computers people are using..
    That includes like laptops, tablets, phones.
  17. We are moving towards getting mobile support going.
  18. And also.. It turns out even for modern browsers this is still a problem. I mean these are not the IE6.
  19. Ehm.. but... even in modern browsers there is a lot of huge differences even at this point in time.
  20. And they don't really seem to agree on how standards should be done
  21. at least not when you get down to the nitty gritty details.
  22. And eh we sort of demand a little rigor
  23. But also yes, wikitext. It is a huge issue for us. There is a lot of ambiguities, there is lot of limitations,
  24. there is a lot of design flaws and they bubble up into the User Interface
  25. and users get really confused about what is going on.
  26. because it doesn't quite work the way Microsoft Word works,
  27. because wikitext is not the same as Microsoft Word.
    It's a data? format.
  28. And so we have to work very hard just to maintain compatibility.
  29. And eh... isn't that so sad.
  30. But we are really hoping to share some of these experiences with you,
  31. not necessarily to make you cry, but because we think there are some interesting challenges,
  32. most of which we have overcome and there are some kinda exciting stories to tell.
  33. So to tell the first one, I'm going to switch over to Roan Kattouw, who is going to talk to us about Wikitext.
  34. Alright, so
    Let's talk wikitext.
  35. Wikitext, like Trevor said, is a limiting factor to us.
  36. And one of the main problems is that if you are a VisualEditor user,
  37. if you are like a VisualEditor-only user, then as far as you are concerned wikitext does not exist.
  38. Like it is our job and our goal to pretend to these people that wikitext has never been there
  39. and will never be there and they can live in this sort of fantasyland where they don't have to deal with it.
  40. Which works [...] for most of our [...] but the reality is that wikitext sort of [..] there.
  41. and users might want to do things that you can't do nicely or can't do at all in wikitext.
  42. And so it ends up being that wikitext limits the users in what they can do.
  43. We can't let them do things that are not representable in wikitext or that produce very ugly wikitext
  44. because people will get upset.
  45. Which means that certain things are not allowed, but they are totally arbitrary and as a user you don't know why.
  46. because you don't know about wikitext, so you don't know about these completely random limitations.
  47. I'll show a few examples of like headaches we've had in our [..]
  48. In wikitext you can do nested lists.
    You can do this perfectly well in HTML as well.
  49. It's perfectly normal, it's the way HTML wants you to do this, is kind of weird,
  50. where it wants you to nest the 2nd level list at the end of the previous list item.
  51. Which is a little bit weird, but whatever fine, it's how everyone does it.
  52. If you insert a line break there, after 'Nested list' and you don't put a star there, then it ends the list completely.
  53. and your 'Bar' ends up completely outside of the list.
    That's also fine
  54. But, if you wanted to put text after the nested list but within the same list item,
  55. so you have a list item 'Foo' and then a nested list and then 'Bar'. You can't do that in wikitext.
  56. It is perfectly valid HTML, it's something that initially would almost ... if you did certain things in VisualEditor, [...]
  57. but you can't do it in wikitext. So we take all sorts of pains to not allow you to do this, because it creates nightmares.
  58. But this is of course completely non-transparent to anyone.
  59. And in general we tend to ignore that newline characters exist.
  60. You also can't really use <pre> formatted text in lists. Wikitext allows you to do it if you use an HTML tag here.
  61. But.. and that actually works just fine.
  62. But it doesn't really work, or it's not really useful
  63. because you try to do this...
  64. which, you wouldn't be using a <pre> tag if you didn't care about the way your newlines were produced,
  65. so you probably are going to add a newline in there.
  66. Then it happily breaks your list for you and throws 'Bar' outside the list and into it's own paragraph,
  67. because clearly that's what you meant, because clearly knows everything [...] a list.
  68. This is superevil. It also shows you how sort of this whole notion of using HTML some places in wikitext
  69. doesn't really work, or HTML and wikitext doesn't really get along that well.
  70. Obviously this means, that if you have pre formatted text in a list and you try to press enter in it,
  71. then VisualEditor needs to do, well not that, because that doesn't work.
  72. and if you try to create this HTML here...
  73. If you try to create something like this, like if the user tried to press Enter inside a <pre> formatted text in a list,
  74. this is what you probably would expect to happen, except that it is completely [..]
  75. [...] so maybe we shouldn't let you do that.
  76. So instead what happens is that if you press Enter inside the list item, then it splits the list item.
  77. We never try to insert any sort of line break like thing there, because we know it explodes.
  78. And also if you select text in a list and try to make it <pre> formatted, we break out of the list.
  79. Because we know that <pre> formatted text in a list is major trouble.
  80. Of course this only makes sense if you [...] and if you are the user, this makes no sense whatsoever.
  81. You can also if you [..] in a list, you can also do this in wikitext and it will do what you expect.
  82. It will create a paragraph break inside your list item.
  83. This isn't the most beautiful wikitext of all time, but it kind of works.
  84. You...
  85. This works, it's not very beautiful..
  86. This is basically what you would get if we [..] work in their own way and insert a paragraph break.
  87. So obviously the solution is to not let the user create paragraphs breaks in list items and they have no idea why.
  88. One of my favorite examples is the [...] link syntax in wikitext is so amazing.
  89. You would think that you can totally embed an image inside the text of a link.
  90. So what this is trying to do is trying to create a link to 'Page' with the link text being 'Foo', an image and then 'Bar'.
  91. This seems reasonable, you can totally do this in HTML, you can totally have an image that's like part of a link action.
  92. If you try to do this in wikitext then everything freaks out and
  93. it decides that the image is more important than the link and it just barfs a bunch of wikitext all over your page.
  94. If we let you try to create a link across an image, then it would try to generate the wikitext like that.
  95. which would then when you render it back would create this garbage and so we cannot really do that
  96. and if you try to link across an image, it will silently cut the link at the image and [..] because we know links and images are trouble
  97. Users have no idea.
  98. If you wanted to do this, this completely sensible HTML, you should totally be able to do this in VisualEditor,
  99. except we don't let you, because if you then try to put the wikitext back, it will be [..]
  100. So those are things that were just broken in wikitext, which means you can't do them in wikitext,
  101. but there are also things that you can kinda do in wikitext except the result is so ugly,
  102. that people that do use wikitext yell at us whenever we do it,
  103. and so we also try and nudge users away from them.
  104. One of these things is,
    is with links.
  105. This is a feature in wikitext where you have link trails.
  106. So if you try to create a link to 'Foo', followed by the word 'bar', you would think that you would [..] like that
  107. but in fact that doesn't actually work that way, because wikitext is helpful and does link trailing.
  108. Where if you write text after a link, it automatically moves it into the link.
  109. So if you are trying to do the conversion like on the first line, it would actually break on you,
  110. because if you then try to convert it back to HTML you'd get something different.
  111. and it would actually go and help you and put bar inside the link
  112. and so instead we have to use a nowiki tag and people started crying and yelling at us for inserting all these [..]
  113. The solution to this problem, if you can call it that, is to, when users type text at the end of the link,
  114. try and make sure that by default that text is always part of the link and so you try and nudge them into creating
  115. content that looks like the thing on the 2nd line, which works and try to make it harder for them
  116. to create content looks like the thing on the 3rd line, because we know that's trouble
  117. This kind of behavior steering is, kind of like, it sort of promotes harmony,
  118. because VE users ended up creating wikitext that looked hideous and that people were upset about..
  119. But.. you know, it's not a real solution and it's completely [...] to people who use it.
  120. You can also put spaces at the beginning of paragraphs, which [...] VE.
  121. You would think that we would just generate wikitext with a space at the beginning,
  122. unfortunately it doesn't work that way, because a space [..] meaningful [...] a <pre> tag.
  123. So what we actually have to do is wrap the space with a nowiki tag and again people get upset at us.
  124. We haven't even solved this problem yet. We think that we might want to detect these spaces
  125. and deliberately ignore them and throw them away.
  126. But you know, you can't really do that, that's not a real solution to a problem.
  127. It's just like trying to steer around various pitfalls again.
  128. Here is another example. You can type '#3' and also you can try to naively serialize that.
  129. But it doesn't do what you expect, because # means that you are trying to do a numbered list.
  130. So you have to wrap the # in a <nowiki>.
  131. Which again, we try to discourage people from doing this, by throwing: "What you typed looks like wikitext"
  132. "This won't really work, are you sure you want to do this?"
  133. Which a more egregious example of this would be
  134. Which a more egregious example of this would be this, where the user actually tries to type wikitext in VE.
  135. We come up with a big flashy warning: "This won't work the way you expect it would"
  136. and if you do save that actually have nowiki tags.
    We can't really prevent that, because this is what we
  137. have to do, to give a faithful representation [...]
  138. So instead we just surface a warning and go like: "Well people don't really like you to do this"
  139. But we can't really stop them.
  140. We have also considered converting this to a link, but we are trying to pretend wikitext doesn't exist.
  141. so that would be incredibly confusing for people who have never used wikitext
  142. and they mash some buttons and all of a sudden they have a link and they have no idea why.
  143. So I talked about solutions to these kinds of problems,
  144. and these are just a few examples, there are like a lot of other things that we steer around,
  145. but they are not really solutions, they are 'solutions' in air quotes, because they are like the lesser of all evils.
  146. we should try and nudge people to do, what we think is the right thing, but the reason it is the right thing,
  147. is [...] understand, so it's just a bunch of crappy workarounds. It's not really [...]
  148. So now Trevor is going to talk about Browsers, which I'm sure we can all agree are lovely things.
  149. I recommend them.
  150. So more specifically to the [...]
  151. I'm really only going to be talking about a browser feature known as ContentEditable.
  152. It is a very magical feature that browsers provide.
  153. Probably the richest feature that they have ever introduced.
  154. It makes HTML like this..
    editable by simply putting a switch.
  155. Job done. Let's go home now. We are all sorted.
  156. But.. It turns out that of all the wonderful features browsers have given us over the past decade or so
  157. this is not one of them.
    ContentEditable is really inconsistent.
  158. It is very overzealous and it's very annoy able.
  159. You are basically always in a defensive position, trying to figure out what just happened.
  160. It doesn't even have events. It does weird things.
  161. Based on what day of the week it is, which way the wind is blowing.
  162. Depending on which browser you are in and what OS you are on.
  163. I think there is a math.random() somewhere in there. I'm not really sure.
  164. We had this idea early on... let's just avoid ContentEditable full stop.
  165. We worked on the WikiEditor.
  166. We tried to make a syntax highlighting version of wikitext editing in a ContentEditable and we ran into a lot of issues.
  167. So we just figured, let's just make a synthetic surface, this is what Google Docs does for instance.
  168. [..] ContentEditable, all the text selection and the blinking cursor and all of that is done with just rendering divs
  169. And we dit it.
    And it worked.
  170. But.. even though we had full control, we also had all the responsibility to implement everything from scratch.
  171. And that is where we got this limitation.
    Things like spellcheck and when you type on mobile
  172. pressing spacebar twice, what does it do.
    And different IME's, and what happens if you swipe.
  173. And mobile text selection is also a big problem, because it works very different and looks very different
  174. from the way it does in desktop browsers.
  175. All these things are stacking up against us and we sort of maybe we have to revisit ContentEditable,
  176. because we were quite limited in what we were able to accomplish.
  177. So we realized that the reason that our ContentEditable experience was so bad,
  178. was because we were making the DOM the center of our application.
  179. That everything in our application, the Data was in the DOM
  180. and the ContentEditable was having it's way with it, without our permission, most of the time.
  181. And the View, which was ContentEditable, was right there in the DOM.
  182. And of course the controller was relying on events from the DOM. That's what put us in that defensive position.
  183. The truth is that this was they way ContentEditable was designed to be used.
  184. So it seemed sensible. But it really set us up for failure.
  185. We realized that what we needed to do, was to come up with a different architecture completely.
  186. Where we simply just use ContentEditable for the little things that it is good for, like rendering
  187. text selection and some, but not all, of our input, because even the events that it gives sometimes are telling lies
  188. so we pretty much have to monitor it, repeatedly, over and over and over and check up and see what it is doing
  189. It is sort of resource intensive.
  190. This whole experience is really just taught us one thing: Browsers are dangerous.
  191. They lie to you, they will waste your time.
  192. They are bound to make you look foolish, and they are toys.
  193. Using a browser to make an application on Wikipedia, is like using my 7 year old daughter's
  194. play kitchen to run a restaurant. Everything seems to be there, but you got to use your imagination.
  195. And that is what I think a lot of VisualEditor engineering is, coming up with very imaginative ways to
  196. overcome the toy-like state of browsers.
  197. Which we hit all the time. So my recommendation to anybody doing [..] development, is to: Protect yourself.
  198. By scrapping. And that is exactly what we do. That is the architecture that we came up with.
  199. You scrap the DOM completely, to the point where we are really seeing it as a thin rendering client
  200. with some input and keep browsers on a very short leash and to give them a minimal amount of control.
  201. That is my recommendation to you all. And now to talk about the troubles of Operating Systems..
  202. and how they effect our work, is: Ed Sanders
  203. Hello
  204. So I'm going to talk to you about something specifically bad about ContentEditable,
  205. which is: copy-paste.
  206. Here is the good news: ContentEditable gives you copy paste.
  207. You can press Ctrl-C, put stuff on the clipboard, you press Ctrl-V it takes out of the clipboard
  208. and that is pretty much half the job done for you. We don't have to [..] the data in some fake clipboard
  209. intercept key events and [..]
  210. There is even more good news. Brought to you by Clippy. It has a bunch of events that are actually quite useful.
  211. So not only are there oncopy and onpaste events. But they happen before the copy and before the paste.
  212. So if you have the oncopy event fired, that means the data hasn't been written to the clipboard yet.
  213. Which turns out to be really useful, because you can actually move someones selection,
  214. just before it writes the data to the clipboard and change what goes into the clipboard.
  215. Even more good news, there is an API, with getData and setData, so you can write stuff directly into the clipboard.
  216. This is only available on copy and paste events. And we can make directly set whatever the hell we want in there.
  217. With an asterisk, because if there is anyone from Mozilla here, we need to talk...
  218. On to the not so good news.
  219. It's really bad. It's really inconsistent. Copy paste is to ContentEditable, what ContentEditable is to browsers.
  220. It's like, it's the worst of the worst.
  221. If we are talking about Trevor's play kitchen
  222. This is like using Play-Doh to make a play kitchen to run the restaurant.
  223. It's just, every browser, there is no documentation, every browser does it somewhat differently,
  224. and this may or may not change next week.
  225. As I mentioned earlier, that beautiful API that would let us do whatever we want in getting the clipboard data,
  226. take whatever we want out... only works in Chrome.
  227. So unfortunately, we have to support more that one browser, so we need to come up with another method.
  228. That will work in Firefox and maybe even IE one day.
  229. Let's have a look at what we actually want to do in VisualEditor.
  230. We have a couple of use cases. There is the easiest one.
  231. Which is to copy some text from the top of your document and paste it a bit lower.
  232. In that case, you cannot choose a favorite clipboard, because we can just use the internal data
  233. that is already in our model, as Trevor mentioned we have taken the model out of ContentEditable.
  234. we store all our data in the [..] So every time we get copy, we can say: "Oh, you selected from 1 to 6"
  235. and then when you hit paste, it gives us the same thing, you can just move it out.
  236. Do one copy from one VE instance to another.
  237. That means, getting all this rich data, like templates or images, and making sure that goes into the
  238. clipboard properly.
  239. And we also might want to copy into a Word document.
    So we need to make sure that what goes into the Word
  240. document is actually, clean HTML.
  241. So you might have thought, just copy between the instances, well we can just take our internal data and JSON serialize it.
  242. But then if you paste that into Word, then you are going to be like, wow what just happened there.
  243. I copied like a paragraph in an editor and now I've got [..]
  244. And people may also want to copy stuff from the website and paste it into the.. maybe not so much Wikipedia,
  245. because you know [..]
  246. So some solutions
  247. 1. We have this thing called DM HTML, which isn't the ContentEditable HTML, because ContentEditable HTML
  248. will randomly [..] your HTML, we keep a [..] copy of the DM HTML, which is what gets send back to the server
  249. when you hit save. So we can put that on the clipboard.
  250. If you put a template that is a table [..] to the table, replace it with a little marker saying: This is info box [..]
  251. So if you put that in the clipboard, when you paste to another VisualEditor instance, you get a template and not just the rendering of a template.
  252. which is a table and a bunch of random stuff, [..]
  253. If we can also put in the clipboard some sort of marker, for internal copy paste,
  254. so we can say, oh this copy actually came from VisualEditor, then when we hit paste we can say:
  255. Well this was a VisualEditor copy, was it from the same window that we are currently in?
  256. If it is, then we can just draw the data from our internal data structure.
  257. So [..]
    Things get easy
  258. We can use the plain clipboard data. We put our DM HTML in the HTML part of the clipboard.
  259. BTW. the clipboard has a plain text area, an HTML area and sort of random custom metadata.
  260. And then we can set a custom key pointing to some internal store for the actual internal data, if they need to be a paste.
  261. And that's not too bad. There's a few problems with actually setting the data directly [..]
  262. Here is the hard way, which is what happens if you have Firefox or Internet Explorer.
  263. You hit copy and as you saw earlier, we have really early events. So we take your selection, which is in the CE.
  264. And we then make generous and DM HTML, put it in a hidden text area, move our selection to the text area, then we wait a bit, wait for the copy to happen. [..]
  265. And then we put everything back where we found it. So slightly convoluted process.
  266. Job done.
  267. Not so fast.
  268. Mo' problems
  269. The ContentEditable clipboard has a habit of tweaking your HTML, so that it looks better.
  270. Internet Explorer in particular throws away lot's of whitespace, that's not so bad.
  271. Firefox, [..] we need to talk again. They throw away, a whole bunch of attributes, such as RDFa.
  272. That's quite unfortunate for us, because we use RDFa to define all template metadata.
  273. So if you are in FireFox and you try to do this, you just throw away all your template metadata and you just be left with [..]
  274. We can work around this by serializing all the templates
  275. which we think CE might destroy, which we put in another template [..] another attribute [..] won't destroy.
  276. Element destruction
  277. Empty spans, we use empty spans in Mozilla to store this internal templating and then Mozilla decides to destroy it.
  278. Because you didn't mean to have an empty span there right ?
  279. So a little hack we can do there is to have a [..] and that sort of protects it... atm.
  280. And reordering. If you sort of copy just a table cell and try to paste that in a paragraph it might sort of wrap it in tables, it might move the paragraph outside [..]
  281. so we need to make sure that when we do do this fake paste [..] trip, that we paste into the right sort of content.
  282. End..
    Almost
  283. As I've mentioned. We don't think we've got this completely sorted out.
  284. We get reports of bugs. We'd love you to try and just fire up VisualEditor in your browser,
  285. copy and paste and stuff and then people get it to break again.
  286. And also as I've mentioned a few times, [..]
  287. And that was that.