Last modified: 2014-10-16 07:53:35 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T37704, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35704 - (inline-styles) Deprecate inline styles (tracking)
(inline-styles)
Deprecate inline styles (tracking)
Status: NEW
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
unspecified
All All
: Low enhancement with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: tracking
: 53866 (view as bug list)
Depends on: 30887 31591 34878 36030 36076
Blocks: tracking 49440
  Show dependency treegraph
 
Reported: 2012-04-04 18:50 UTC by Tomasz Finc
Modified: 2014-10-16 07:53 UTC (History)
24 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Tomasz Finc 2012-04-04 18:50:20 UTC
Loading http://nl.m.wikipedia.org/wiki/Titanic_(schip) in the iOS simulator shows a very poorly rendered set of info boxes.
Comment 1 Jon 2012-04-05 11:09:54 UTC
Another example of problematic inline styles just like bug 31591
Setting float and width seem to be the cause these issues. We can scrape these out but that will not be very efficient.
Comment 2 Jon 2012-04-18 19:56:24 UTC
bug 36076 is also caused by inline styling (usually how I check this is doing $("*").attr("style", ""); in my browser console window
Comment 3 Jon 2012-04-18 20:04:49 UTC
How feasible in terms of performance would it be to remove all inline styles from an article apart from ones which are marked in a special way e.g. have a class mobile-safe ?

This would allow people to still use them but use them responsibly
Comment 4 Jon 2012-04-19 14:29:03 UTC
bug 36030 is another example of problems caused by this
Comment 5 Jon 2012-04-19 14:46:07 UTC
also see bug 30887
Comment 6 Jon 2012-04-19 15:24:07 UTC
also bug 34878
Comment 7 Jon 2012-04-19 17:22:55 UTC
Started a discussion on wikitech-l list:

http://lists.wikimedia.org/pipermail/wikitech-l/2012-April/060224.html
Comment 8 Jon 2012-05-02 07:45:27 UTC
From the feedback:

Also visiting
http://en.m.wikipedia.org/w/index.php?title=Selfridge_Air_National_Guard_Base#_
shows the dot on the map in Canada

This is due to width:auto !important defined on .thumb .thumbinner[style]
Comment 9 Jon 2012-05-07 22:19:27 UTC
All these bad rules currently have to be overridden in hacks.css via tag[style] css rules
The latest issue we have encountered with this is slowdown in scrolling on iOS 4.x (see bug 36605).

We're yet to find a suitable solution to this problem but we seemed to be getting to the following situation:

* Allow users to define css rules rather than inline css
* Clean up templates, possibly allowing flagging of templates to make this job easier
* In the long term considering the turning off of inline styles on the mobile site

The remaining issue there is XSS and the possibility of damaging ui's (for instance a user could update a css stylesheet to make all content invisible).
Comment 10 Jon 2012-05-07 22:20:20 UTC
*** Bug 36605 has been marked as a duplicate of this bug. ***
Comment 11 Jon 2012-05-07 22:56:30 UTC
The licensing section also renders horrible on smaller screens - yet again there are some inline styles with fixed widths of 90px causing this

http://en.m.wikipedia.org/wiki/File:Nikolic_Tomislav.jpeg#section_2
Comment 12 Jon 2012-06-03 09:52:30 UTC
Setup the page http://www.mediawiki.org/wiki/Making_MediaWiki_Mobile_Friendly to document these problems.
Comment 13 Helder 2012-06-28 00:44:20 UTC
This seems to be a tracking bug, so I'm adding it as a blocker for bug 2007.
Comment 14 Jon 2012-07-27 19:23:21 UTC
Forgot to link to this > http://www.mediawiki.org/wiki/Deprecating_inline_styles
Comment 15 Jon 2012-08-02 20:41:00 UTC
*** Bug 38833 has been marked as a duplicate of this bug. ***
Comment 16 Jon 2012-10-10 17:58:05 UTC
For this to be solved we need the following things
1) A mechanism to allow pages to have associated stylesheets where css rules can live
2) A community activity of migrating inline styles in wiki pages to these stylesheets
3) Stripping inline styles from the mobile site
4) At a future date stripping inline style support in wikitext

If anyone has the time to work on this, I will work hard to unblock any obstacles people face.
Comment 17 Jon 2012-10-12 18:36:39 UTC
Captured this as a story:
https://mingle.corp.wikimedia.org/projects/mobile/cards/221
Comment 19 Gerrit Notification Bot 2013-06-12 00:38:18 UTC
Related URL: https://gerrit.wikimedia.org/r/68123 (Gerrit Change I557f5abd54d73c288c23c00ecc9f568400355d7c)
Comment 20 Jon 2013-06-26 00:23:35 UTC
Opened the RFC https://www.mediawiki.org/wiki/Requests_for_comment/Allow_styling_in_templates

This would allow us to shift styling to stylesheets and allow us to write mobile specific rules.
Comment 21 C. Scott Ananian 2013-08-23 15:30:28 UTC
Note that there is apparently a robust polyfill for the new scoped-CSS proposal, at https://github.com/PM5544/scoped-polyfill .

So we could move forward with just scoped CSS, and add the polyfill to our pages to Make It Work Everywhere.  That's one idea, at least.
Comment 22 Matthew Flaschen 2013-08-24 04:36:11 UTC
(In reply to comment #21)
> So we could move forward with just scoped CSS, and add the polyfill to our
> pages to Make It Work Everywhere.  That's one idea, at least.

The problem is unbalanced templates.  We could try an approach like my suggestion at https://www.mediawiki.org/wiki/Talk:Requests_for_comment/Allow_styling_in_templates#What_measures_need_to_be_made_to_take_into_account_performance_and_security

Or, we could support template styling only for balanced templates.  I'm not sure if this is detectable/enforceable, but it might also help Parsoid/VE if there's a way to check it.
Comment 23 C. Scott Ananian 2013-08-26 18:11:58 UTC
I don't think that unbalanced templates are a problem.  They would allow the style to leak, but that's no different from how unbalanced templates can currently open/close unbalanced tags, etc.  We already have a sanitizer to take care of the HTML issues, it should also be able to ensure that the scope of the template doesn't escape out of the content area.
Comment 24 MZMcBride 2013-08-26 22:20:51 UTC
(In reply to comment #23)
> We already have a sanitizer to take care of the HTML issues, it should also be
> able to ensure that the scope of the template doesn't escape out of the
> content area.

Indeed.

Though, for clarity, I believe it's HTMLTidy, not includes/Sanitizer.php, that currently catches unclosed <div>s, etc.
Comment 25 Jon 2013-09-06 22:30:41 UTC
*** Bug 53866 has been marked as a duplicate of this bug. ***
Comment 26 Gabriel Wicke 2013-09-10 02:01:38 UTC
(In reply to comment #23)
> I don't think that unbalanced templates are a problem.  They would allow the
> style to leak, but that's no different from how unbalanced templates can
> currently open/close unbalanced tags, etc.  We already have a sanitizer to
> take
> care of the HTML issues, it should also be able to ensure that the scope of
> the
> template doesn't escape out of the content area.

The sanitizer knows nothing about nesting. Style elements need to be wrapped around a subtree, which is where you run into trouble if your template output is not a subtree.

Parsoid infers and encapsulates DOM subtrees affected by one or more templates. Scoped styles could piggy-back on this information, but then you still have to solve the issue of merging styles from multiple templates in a way that hopefully resembles the author's intentions.
Comment 27 Matthew Flaschen 2013-09-10 03:01:27 UTC
(In reply to comment #22)

> The problem is unbalanced templates.  We could try an approach like my
> suggestion at
> https://www.mediawiki.org/wiki/Talk:Requests_for_comment/
> Allow_styling_in_templates#What_measures_need_to_be_made_to_take_into_account
> _performance_and_security

Jon and I talked about this for a while.  We didn't reach conclusions, but he pointed out you could use <style scoped> purely around bodyContent:

<div id="bodyContent">
    <style scoped>
      /* ... */
    </style>
</div>

This would be an alternative to the CSS rewriting idea at https://www.mediawiki.org/wiki/Talk:Requests_for_comment/Allow_styling_in_templates#What_measures_need_to_be_made_to_take_into_account_performance_and_security .

This dodges the unbalanced template issue, while still preventing styles from leaking into the chrome (non-content) areas.  However, it does nothing to attempt to prevent templates from interfering with each other.

However, I found a general issue with <style scoped> while reading about it (http://html5doctor.com/the-scoped-attribute/#compatibility).  Since old browsers will simply drop the scoped, they will treat it as a regular style, meaning there's no scoping.

It seems like this can be avoided with polyfills in at least some browsers (e.g. https://gist.github.com/richtr/4039383 works for me), but if JavaScript is disabled (and possibly for old browsers), it falls back to being global CSS.

There is a proposal for a <scopedstyle> tag that may mitigate this.
Comment 28 Gabriel Wicke 2013-09-23 15:45:03 UTC
I added an alternative proposal at https://www.mediawiki.org/wiki/Talk:Requests_for_comment/Allow_styling_in_templates#Class-triggered_CSS_includes

Gist: Compile CSS definitions from a CSS namespace whenever matching prefixed classes are used in the content.
Comment 29 Samuel Bronson 2014-02-14 17:51:48 UTC
(Note: This looks like it has changed from being a tracking bug to discussing what a wikitext version of "<style scoped>" should look like, and how to implement it.  Also, it doesn't look very mobile-specific anymore to me.)

Personally, I think the simplest approach would be:

  1. Use basically the same syntax as HTML5 does in the wikitext, only without the first-child restriction. 

  2. *Do* preprocess the style text, I can imagine some rather neat parameterized templates.  (Catching runaway tags in the page content is important, of course, but I'm fairly certain this was already the case?)

  3. *Don't* try to do anything complicated to restrict the effects to the output of one template; it sounds like a lot of work only to make the feature *less* useful.

  4. Transform the pre-processed scoped CSS in the input into non-scoped CSS in the output (by generating a class name for each unique scoped stylesheet, adding that class to the relevant nodes, and appropriately prefixing each selector), because only Mozilla appears to support the feature by default, JS-based polyfill only works when JS is on, and you need to sanitize the CSS anyway.
Comment 30 Matthew Flaschen 2014-02-14 19:05:59 UTC
I agree this is not really a MobileFrontend bug anymore.  This was discussed at the architecture summit.  See https://www.mediawiki.org/wiki/Architecture_Summit_2014/UI_styling and https://www.mediawiki.org/wiki/Talk:Architecture_Summit_2014/UI_styling .

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links