aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimo Tijhof <krinkle@fastmail.com>2025-03-25 23:11:43 -0700
committerTimo Tijhof <krinkle@fastmail.com>2025-03-25 23:11:43 -0700
commite40e135b2d4117d41d88c90c112f9e602c3f88ce (patch)
treee63abf28825d4b778fae0a70b7e77163c28d85f7
parent0e3a562d6ea3f9529d995a3494b741486ef3747a (diff)
downloadmediawikicore-e40e135b2d4117d41d88c90c112f9e602c3f88ce.tar.gz
mediawikicore-e40e135b2d4117d41d88c90c112f9e602c3f88ce.zip
ResourceLoader: Remove unused 'dir' parameter to load.php
When MediaWiki creates load.php URLs, in OutputPage and via RL\Client, it sets 'lang', not 'dir'. The direction is automatically derived from the language, which makes the library easier to use for developers, and also avoids a potentially confusing scenario in which the two are different (e.g. lang=he and dir=ltr would not make sense, and would further risk poisoning LTR content in an RTL/Hebrew-related cache somewhere). Bug: T225845 Change-Id: I14905c85bb5e3bb47a681dc99668b92844d22f04
-rw-r--r--includes/ResourceLoader/Context.php11
-rw-r--r--tests/phpunit/ResourceLoaderTestCase.php10
-rw-r--r--tests/phpunit/includes/ResourceLoader/ContextTest.php14
-rw-r--r--tests/phpunit/includes/ResourceLoader/FileModuleTest.php14
4 files changed, 13 insertions, 36 deletions
diff --git a/includes/ResourceLoader/Context.php b/includes/ResourceLoader/Context.php
index 3ee03704a36c..c2c52602c98e 100644
--- a/includes/ResourceLoader/Context.php
+++ b/includes/ResourceLoader/Context.php
@@ -220,14 +220,9 @@ class Context implements MessageLocalizer {
public function getDirection(): string {
if ( $this->direction === null ) {
- $direction = $this->getRequest()->getRawVal( 'dir' );
- if ( $direction === 'ltr' || $direction === 'rtl' ) {
- $this->direction = $direction;
- } else {
- // Determine directionality based on user language (T8100)
- $this->direction = MediaWikiServices::getInstance()->getLanguageFactory()
- ->getLanguage( $this->getLanguage() )->getDir();
- }
+ // Determine directionality based on user language (T8100)
+ $this->direction = MediaWikiServices::getInstance()->getLanguageFactory()
+ ->getLanguage( $this->getLanguage() )->getDir();
}
return $this->direction;
}
diff --git a/tests/phpunit/ResourceLoaderTestCase.php b/tests/phpunit/ResourceLoaderTestCase.php
index e12d0b2cc3f2..2de39a8a42d8 100644
--- a/tests/phpunit/ResourceLoaderTestCase.php
+++ b/tests/phpunit/ResourceLoaderTestCase.php
@@ -25,7 +25,6 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
/**
* @param array|string $options Language code or options array
* - string 'lang' Language code
- * - string 'dir' Language direction (ltr or rtl)
* - string 'modules' Pipe-separated list of module names
* - string|null 'only' "scripts" (unwrapped script), "styles" (stylesheet), or null
* (mw.loader.implement).
@@ -34,13 +33,11 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
*/
protected function getResourceLoaderContext( $options = [], ?ResourceLoader $rl = null ) {
if ( is_string( $options ) ) {
- // Back-compat for extension tests
$options = [ 'lang' => $options ];
}
$options += [
'debug' => 'true',
'lang' => 'en',
- 'dir' => 'ltr',
'skin' => 'fallback',
'modules' => 'startup',
'only' => 'scripts',
@@ -65,12 +62,7 @@ abstract class ResourceLoaderTestCase extends MediaWikiIntegrationTestCase {
'sourcemap' => $options['sourcemap'],
'target' => 'phpunit',
] );
- $ctx = $this->getMockBuilder( Context::class )
- ->setConstructorArgs( [ $resourceLoader, $request ] )
- ->onlyMethods( [ 'getDirection' ] )
- ->getMock();
- $ctx->method( 'getDirection' )->willReturn( $options['dir'] );
- return $ctx;
+ return new Context( $resourceLoader, $request );
}
public static function getSettings() {
diff --git a/tests/phpunit/includes/ResourceLoader/ContextTest.php b/tests/phpunit/includes/ResourceLoader/ContextTest.php
index c570f7addfa4..cf127b1d538a 100644
--- a/tests/phpunit/includes/ResourceLoader/ContextTest.php
+++ b/tests/phpunit/includes/ResourceLoader/ContextTest.php
@@ -104,18 +104,14 @@ class ContextTest extends TestCase {
[ 'lang' => 'he' ],
'rtl',
];
- yield 'explicit LTR' => [
- [ 'lang' => 'he', 'dir' => 'ltr' ],
- 'ltr',
- ];
- yield 'explicit RTL' => [
- [ 'lang' => 'en', 'dir' => 'rtl' ],
+ yield 'RTL variant of LTR language' => [
+ [ 'lang' => 'en-rtl' ],
'rtl',
];
// Not supported, but tested to cover the case and detect change
- yield 'invalid dir' => [
- [ 'lang' => 'he', 'dir' => 'xyz' ],
- 'rtl',
+ yield 'invalid language' => [
+ [ 'lang' => 'invalid-xyz' ],
+ 'ltr',
];
}
diff --git a/tests/phpunit/includes/ResourceLoader/FileModuleTest.php b/tests/phpunit/includes/ResourceLoader/FileModuleTest.php
index a0ea3374a1d9..0bc83008d3ba 100644
--- a/tests/phpunit/includes/ResourceLoader/FileModuleTest.php
+++ b/tests/phpunit/includes/ResourceLoader/FileModuleTest.php
@@ -283,14 +283,8 @@ class FileModuleTest extends ResourceLoaderTestCase {
] );
$expectedModule->setName( 'testing' );
- $contextLtr = $this->getResourceLoaderContext( [
- 'lang' => 'en',
- 'dir' => 'ltr',
- ] );
- $contextRtl = $this->getResourceLoaderContext( [
- 'lang' => 'he',
- 'dir' => 'rtl',
- ] );
+ $contextLtr = $this->getResourceLoaderContext( [ 'lang' => 'en' ] );
+ $contextRtl = $this->getResourceLoaderContext( [ 'lang' => 'he' ] );
// Since we want to compare the effect of @noflip+@embed against the effect of just @embed, and
// the @noflip annotations are always preserved, we need to strip them first.
@@ -313,13 +307,13 @@ class FileModuleTest extends ResourceLoaderTestCase {
] );
$plain->setName( 'test' );
- $context = $this->getResourceLoaderContext( [ 'lang' => 'en', 'dir' => 'ltr' ] );
+ $context = $this->getResourceLoaderContext( [ 'lang' => 'en' ] );
$this->assertEquals(
[ 'all' => ".example { text-align: left; }\n" ],
$plain->getStyles( $context ),
'Unchanged styles in LTR mode'
);
- $context = $this->getResourceLoaderContext( [ 'lang' => 'he', 'dir' => 'rtl' ] );
+ $context = $this->getResourceLoaderContext( [ 'lang' => 'he' ] );
$this->assertEquals(
[ 'all' => ".example { text-align: right; }\n" ],
$plain->getStyles( $context ),