Set explicit direction to ApiHelp headers with module names
authorAmir E. Aharoni <amir.aharoni@mail.huji.ac.il>
Sat, 12 Sep 2015 09:59:38 +0000 (12:59 +0300)
committerAmire80 <amir.aharoni@mail.huji.ac.il>
Fri, 29 Apr 2016 15:06:38 +0000 (18:06 +0300)
Bug: T112364
Change-Id: I28e8e0cbbeb0ff0a41a06cb28fbda26d72725e59

includes/api/ApiHelp.php
resources/src/mediawiki/mediawiki.apihelp.css

index f7539ce..0f0fbdc 100644 (file)
@@ -255,28 +255,43 @@ class ApiHelp extends ApiBase {
                                }
 
                                if ( $module->isMain() ) {
-                                       $header = $context->msg( 'api-help-main-header' )->parse();
+                                       $headerContent = $context->msg( 'api-help-main-header' )->parse();
+                                       $headerAttr = [
+                                               'class' => 'apihelp-header',
+                                       ];
                                } else {
                                        $name = $module->getModuleName();
-                                       $header = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
+                                       $headerContent = $module->getParent()->getModuleManager()->getModuleGroup( $name ) .
                                                "=$name";
                                        if ( $module->getModulePrefix() !== '' ) {
-                                               $header .= ' ' .
+                                               $headerContent .= ' ' .
                                                        $context->msg( 'parentheses', $module->getModulePrefix() )->parse();
                                        }
+                                       // Module names are always in English and not localized,
+                                       // so English language and direction must be set explicitly,
+                                       // otherwise parentheses will get broken in RTL wikis
+                                       $headerAttr = [
+                                               'class' => 'apihelp-header apihelp-module-name',
+                                               'dir' => 'ltr',
+                                               'lang' => 'en',
+                                       ];
                                }
+
+                               $headerAttr['id'] = $anchor;
+
                                $haveModules[$anchor] = [
                                        'toclevel' => count( $tocnumber ),
                                        'level' => $level,
                                        'anchor' => $anchor,
-                                       'line' => $header,
+                                       'line' => $headerContent,
                                        'number' => implode( '.', $tocnumber ),
                                        'index' => false,
                                ];
                                if ( empty( $options['noheader'] ) ) {
-                                       $help['header'] .= Html::element( 'h' . min( 6, $level ),
-                                               [ 'id' => $anchor, 'class' => 'apihelp-header' ],
-                                               $header
+                                       $help['header'] .= Html::element(
+                                               'h' . min( 6, $level ),
+                                               $headerAttr,
+                                               $headerContent
                                        );
                                }
                        } else {
index 7d7b413..a35ce7a 100644 (file)
@@ -3,6 +3,16 @@
        margin-bottom: 0.1em;
 }
 
+.apihelp-header.apihelp-module-name {
+       /*
+        * This element is explicitly set to dir="ltr" in HTML.
+        * Set explicit alignment so that CSSJanus will flip it to "right";
+        * otherwise the alignment will be automatically set to "left" according
+        * to the element's direction, and this will have an inconsistent look.
+        */
+       text-align: left;
+}
+
 div.apihelp-linktrail {
        font-size: smaller;
 }