Page MenuHomePhabricator

Sanitizer shouldn't convert "align" attribute to text-align for non-table-cells
Closed, ResolvedPublic

Description

Author: genio2003

Description:
When I use in a table align="right" doesn't display on the right side...

{| align="right" border="1"

Col 1, row 1
rowspan="2"Col 2, row 1 (and 2)
Col 3, row 1
-
Col 1, row 2
Col 3, row 2
}

with style="float:right;" it works, but before running versions align="right" works, too.

{| style="float:right;" border="1"

Col 1, row 1
rowspan="2"Col 2, row 1 (and 2)
Col 3, row 1
-
Col 1, row 2
Col 3, row 2
}

Version: 1.19.0
Severity: minor

Details

Reference
bz36495

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 12:21 AM
bzimport set Reference to bz36495.

Which browser? Tested firefox, chromium and Opera on https://en.wikipedia.org/wiki/User:MarkAHershberger/sandbox3 and all appeared to work.

genio2003 wrote:

Looks like it works on wikipedia.org sites, but mediawiki.org same problem with the systax like my private wiki (based on Mediawiki 1.19.0)...

ek79501 wrote:

Yes I can confirm this bug. For me its the Align=center. It used to work OK before and its messed up some formatting. It works on Wikipedia and it doesn't work on a new 1.19.
{| align="center"
is rendered on a new MW 1.19 and on Mediawiki.org as:
<table style="text-align: center;">

But it renders differently on en.Wikipedia.org:
<table align="center">

ek79501 wrote:

There's two additional bugs (duplicate). One of them has a suggested solution for correct CSS (I didn't verify the solution to see if its the best):
https://bugzilla.wikimedia.org/show_bug.cgi?id=36586

The other duplicate is:
https://bugzilla.wikimedia.org/show_bug.cgi?id=37114

  • align="left" and align="right" have been deprecated for years. All browsers around today map this internally to float:left and float:right respectively.
  • float: center; doesn't exist and has never existed. This is a common mistake but not a bug.
  • As of MediaWiki 1.19 the Sanitizer class converts these to CSS (but only if the wiki is in HTML5 mode, which it is by default, but Wikipedia has HTML5 mode disabled. MediaWiki.org has it enabled and your own install will have it enabled by default as well)
  • Short term solution: Do not use align="", valign="", clear="" etc. Instead use CSS or inline style="" as these attributes have all been deprecated for a long time.
  • Long term solution: align="" is converted by Sanitizer to only text-align. For left/right it should also include float (depending on the element).
  • Bug 37114 has been marked as a duplicate of this bug. ***
  • Bug 36586 has been marked as a duplicate of this bug. ***

(aggregated from the dupes)

  • align="*" on table-cells (left, right, center) -> style="text-align: *;"
  • align="*" on other elements (left, right) -> style="float: *;"
  • align="center" on other elements -> style="margin-left: auto; margin-right: auto;"