Page MenuHomePhabricator

OOUI PHP: Be able to set widgets' direction to RTL/LTR
Closed, ResolvedPublic

Description

(Migrated from http://etherpad.wikimedia.org/p/OOUIPHP)

Q: Grid layout needs to know whether it is LTR or RTL, how do we teach it that? This looks impossible to fix unless we introduce some global thingy to define the direction to use for all OOUI elements (static method/property on OoUiElement, possibly), or store this information in every Element.
A: This is a very good question, I want to ask Roan about his thoghts here, but my fist thoughts are that we will need to provide the equivelent to the way we detect the direction as what is on the client or keeping the libraries in sync will be quite difficult


Version: unspecified
Severity: enhancement

Details

Reference
bz72584

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:54 AM
bzimport added a project: OOUI.
bzimport set Reference to bz72584.

In JS, there's a static method OO.ui.Element.getDir that is used to determine direction. It goes like this:

OO.ui.Element.getDir = function ( obj ) {
	<blah blah>
	<'obj' is usually 'document.body' at this point>
	return $( obj ).css( 'direction' );
};

In PHP, we have this so far:

class OoUiElement extends OoUiTag {
	<snip>
	public static function getDir() {
		// TODO: Figure out a way to override this functionality when used within MediaWiki, and use
		// $wgLang->getDir() to get the user interface direction
		return 'ltr';
	}
}

Subclassing OoUiElement doesn't look viable, so that leaves us with the option of adding OoUiElement::setDir() method that the environment may call to set things up (similarly to how one calls OoUiTheme::setSingleton( new OoUiMediaWikiTheme() )).

If we also did this in JS, and used that value as a fallback, and went a bit further in that direction, it could probably become possible to use JS OOUI server-side, too; so that might not be a bad idea in general.

Change 170341 had a related patch set uploaded by Bartosz Dziewoński:
OOUI PHP: Support RTL text direction

https://gerrit.wikimedia.org/r/170341

There's also the bigger question of whether we want to support per-document or per-element directionality.

Currently JS sorta-kinda supports per-element directionality, but it's largely by chance – per comment 1, we just look at CSS 'direction' property and use that. We don't support changing the direction of existing elements. I don't think anybody has tried actually using this and seeing what happens when you mix-and-match.

I discussed it with Moriel on IRC and for now we're only going to support per-document directionality in PHP, and implement per-element support when it turns out that we actually need it.

Change 170341 merged by jenkins-bot:
OOUI PHP: Support RTL text direction

https://gerrit.wikimedia.org/r/170341